diff --git a/examples/arduino/teensy41-http/teensy41-http.ino b/examples/arduino/teensy41-http/teensy41-http.ino index f9368630..90a6d54e 100644 --- a/examples/arduino/teensy41-http/teensy41-http.ino +++ b/examples/arduino/teensy41-http/teensy41-http.ino @@ -25,7 +25,7 @@ uint64_t mg_millis(void) { // Let Mongoose use our uptime function // Simple HTTP server that runs on port 8000 // Mongoose event handler function, gets called by the mg_mgr_poll() // See https://mongoose.ws/documentation/#2-minute-integration-guide -static void simple_http_listener(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void simple_http_listener(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { // The MG_EV_HTTP_MSG event means HTTP request. `hm` holds parsed request, // see https://mongoose.ws/documentation/#struct-mg_http_message diff --git a/examples/arduino/w5500-http/w5500-http.ino b/examples/arduino/w5500-http/w5500-http.ino index 93959785..abf3fe75 100644 --- a/examples/arduino/w5500-http/w5500-http.ino +++ b/examples/arduino/w5500-http/w5500-http.ino @@ -38,7 +38,7 @@ void setup() { // Setup HTTP listener. Respond "ok" on any HTTP request mg_http_listen( &mgr, "http://0.0.0.0", - [](struct mg_connection *c, int ev, void *ev_data, void *fn_data) { + [](struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "ok\n"); }, &mgr); diff --git a/examples/arduino/w5500-mqtt/net.c b/examples/arduino/w5500-mqtt/net.c index 07f90dd9..e756410b 100644 --- a/examples/arduino/w5500-mqtt/net.c +++ b/examples/arduino/w5500-mqtt/net.c @@ -15,7 +15,7 @@ void mqtt_publish(const char *message) { if (mqtt_connection) mg_mqtt_pub(mqtt_connection, &opts); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_MQTT_OPEN) { MG_INFO(("%lu CONNECTED to %s", c->id, MQTT_SERVER)); struct mg_mqtt_opts opts = {}; diff --git a/examples/captive-dns-server/main.c b/examples/captive-dns-server/main.c index e69e501b..db60f53e 100644 --- a/examples/captive-dns-server/main.c +++ b/examples/captive-dns-server/main.c @@ -20,7 +20,7 @@ uint8_t answer[] = { 1, 2, 3, 4 // 4 bytes - IP address }; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { c->is_hexdumping = 1; } else if (ev == MG_EV_READ) { @@ -41,7 +41,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } mg_iobuf_del(&c->recv, 0, c->recv.len); } - (void) fn_data; (void) ev_data; } diff --git a/examples/device-dashboard/net.c b/examples/device-dashboard/net.c index 91d29511..2d8d3b1c 100644 --- a/examples/device-dashboard/net.c +++ b/examples/device-dashboard/net.c @@ -51,7 +51,7 @@ int ui_event_next(int no, struct ui_event *e) { // SNTP connection event handler. When we get a response from an SNTP server, // adjust s_boot_timestamp. We'll get a valid time from that point on -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { uint64_t *expiration_time = (uint64_t *) c->data; if (ev == MG_EV_OPEN) { *expiration_time = mg_millis() + 3000; // Store expiration time in 3s @@ -62,7 +62,6 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_POLL) { if (mg_millis() > *expiration_time) c->is_closing = 1; } - (void) fn_data; } static void timer_sntp_fn(void *param) { // SNTP timer function. Sync up time @@ -262,9 +261,9 @@ static void handle_device_eraselast(struct mg_connection *c) { } // HTTP request handler function -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ACCEPT) { - if (fn_data != NULL) { // TLS listener! + if (c->fn_data != NULL) { // TLS listener! struct mg_tls_opts opts = {0}; opts.cert = mg_unpacked("/certs/server_cert.pem"); opts.key = mg_unpacked("/certs/server_key.pem"); diff --git a/examples/embedded-filesystem/main.c b/examples/embedded-filesystem/main.c index 3a42fdf3..c1813266 100644 --- a/examples/embedded-filesystem/main.c +++ b/examples/embedded-filesystem/main.c @@ -6,7 +6,7 @@ const char *s_listening_url = "http://0.0.0.0:8000"; // HTTP request handler function -void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_serve_opts opts = { .root_dir = "/web_root", @@ -14,7 +14,6 @@ void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { }; mg_http_serve_dir(c, ev_data, &opts); } - (void) fn_data; } int main(void) { diff --git a/examples/esp32/micropython/mongoose/main.c b/examples/esp32/micropython/mongoose/main.c index 6a72d005..fa2914a2 100644 --- a/examples/esp32/micropython/mongoose/main.c +++ b/examples/esp32/micropython/mongoose/main.c @@ -8,9 +8,8 @@ static void t_fn(void *arg) { // Tick periodically (void) arg; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "hi\n"); - (void) fn_data; (void) ev_data; } diff --git a/examples/esp8266/http-client-server/src/main/main.c b/examples/esp8266/http-client-server/src/main/main.c index 8399f37d..6aa027e8 100644 --- a/examples/esp8266/http-client-server/src/main/main.c +++ b/examples/esp8266/http-client-server/src/main/main.c @@ -9,8 +9,8 @@ #define SERVER_URL "http://0.0.0.0:80" #define CLIENT_URL "http://info.cern.ch" -// Event handler for an server (accepted) connection -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +// Event handler for a server (accepted) connection +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { mg_http_reply(c, 200, "", "Hello from ESP!\n"); } @@ -20,7 +20,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { // To enable TLS for HTTP, // 1. Copy "ca.pem" file to the ESP8266 flash FS // 2. Add TLS init snippet for the connection, see examples/http-client -static void cb2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb2(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_CONNECT) { struct mg_str s = mg_url_host(CLIENT_URL); mg_printf(c, "GET / HTTP/1.0\r\nHost: %.*s\r\n\r\n", (int) s.len, s.ptr); diff --git a/examples/file-upload-html-form/main.c b/examples/file-upload-html-form/main.c index 8fa06e20..ce08a515 100644 --- a/examples/file-upload-html-form/main.c +++ b/examples/file-upload-html-form/main.c @@ -16,7 +16,7 @@ // // Also, consider changing -DMG_IO_SIZE=SOME_BIG_VALUE to increase IO buffer // increment when reading data. -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len, @@ -35,7 +35,6 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/file-upload-multiple-posts/main.c b/examples/file-upload-multiple-posts/main.c index b1b8c4b9..8895da52 100644 --- a/examples/file-upload-multiple-posts/main.c +++ b/examples/file-upload-multiple-posts/main.c @@ -6,7 +6,7 @@ // HTTP request handler function. It implements the following endpoints: // /upload - Saves the next file chunk // all other URI - serves web_root/ directory -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/upload")) { @@ -25,7 +25,6 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/file-upload-single-post/main.c b/examples/file-upload-single-post/main.c index 982e918e..b9bd6423 100644 --- a/examples/file-upload-single-post/main.c +++ b/examples/file-upload-single-post/main.c @@ -11,7 +11,7 @@ // HTTP request handler function. It implements the following endpoints: // /upload - Saves the next file chunk // all other URI - serves web_root/ directory -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { // Parse the incoming data ourselves. If we can parse the request, // store two size_t variables in the c->data: expected len and recv len. @@ -38,7 +38,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } } } - (void) fn_data, (void) ev_data; + (void) ev_data; } int main(void) { diff --git a/examples/http-client/main.c b/examples/http-client/main.c index a1f76cdd..965b2207 100644 --- a/examples/http-client/main.c +++ b/examples/http-client/main.c @@ -15,7 +15,7 @@ static const char *s_post_data = NULL; // POST data static const uint64_t s_timeout_ms = 1500; // Connect timeout in milliseconds // Print HTTP response and signal that we're done -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // Connection created. Store connect expiration time in c->data *(uint64_t *) c->data = mg_millis() + s_timeout_ms; @@ -50,9 +50,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; printf("%.*s", (int) hm->message.len, hm->message.ptr); c->is_draining = 1; // Tell mongoose to close this connection - *(bool *) fn_data = true; // Tell event loop to stop + *(bool *) c->fn_data = true; // Tell event loop to stop } else if (ev == MG_EV_ERROR) { - *(bool *) fn_data = true; // Error, tell event loop to stop + *(bool *) c->fn_data = true; // Error, tell event loop to stop } } diff --git a/examples/http-proxy-client/main.c b/examples/http-proxy-client/main.c index 35adb96b..aea5d000 100644 --- a/examples/http-proxy-client/main.c +++ b/examples/http-proxy-client/main.c @@ -10,8 +10,8 @@ #include "mongoose.h" // Print HTTP response and signal that we're done -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - const char *url = fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + const char *url = c->fn_data; static bool connected; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; diff --git a/examples/http-restful-server/main.c b/examples/http-restful-server/main.c index 9e2b76d4..b00c5d1e 100644 --- a/examples/http-restful-server/main.c +++ b/examples/http-restful-server/main.c @@ -56,8 +56,8 @@ static const char *s_tls_key = // We use the same event handler function for HTTP and HTTPS connections // fn_data is NULL for plain HTTP, and non-NULL for HTTPS -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - if (ev == MG_EV_ACCEPT && fn_data != NULL) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { + if (ev == MG_EV_ACCEPT && c->fn_data != NULL) { struct mg_tls_opts opts = { #ifdef TLS_TWOWAY .ca = mg_str(s_tls_ca), @@ -89,7 +89,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/http-reverse-proxy/main.c b/examples/http-reverse-proxy/main.c index 2d7d47c1..d61225d0 100644 --- a/examples/http-reverse-proxy/main.c +++ b/examples/http-reverse-proxy/main.c @@ -36,8 +36,8 @@ static void forward_request(struct mg_http_message *hm, (int) hm->uri.len, hm->uri.ptr)); } -static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_connection *c2 = (struct mg_connection *) fn_data; +static void fn2(struct mg_connection *c, int ev, void *ev_data) { + struct mg_connection *c2 = (struct mg_connection *) c->fn_data; if (ev == MG_EV_READ) { // All incoming data from the backend, forward to the client if (c2 != NULL) mg_send(c2, c->recv.buf, c->recv.len); @@ -48,8 +48,8 @@ static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { (void) ev_data; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_connection *c2 = fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + struct mg_connection *c2 = c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; // Client request, create backend connection Note that we're passing diff --git a/examples/http-server/main.c b/examples/http-server/main.c index f2efbc5f..9e1e19ae 100644 --- a/examples/http-server/main.c +++ b/examples/http-server/main.c @@ -18,7 +18,7 @@ static void signal_handler(int signo) { // Event handler for the listening connection. // Simply serve static files from `s_root_dir` -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = ev_data, tmp = {0}; struct mg_str unknown = mg_str_n("?", 1), *cl; @@ -33,7 +33,6 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { (int) hm->uri.len, hm->uri.ptr, (int) tmp.uri.len, tmp.uri.ptr, (int) cl->len, cl->ptr)); } - (void) fn_data; } static void usage(const char *prog) { diff --git a/examples/http-streaming-client/main.c b/examples/http-streaming-client/main.c index 5c46a1a8..de4c9082 100644 --- a/examples/http-streaming-client/main.c +++ b/examples/http-streaming-client/main.c @@ -15,7 +15,7 @@ static const char *s_url = "http://info.cern.ch"; // Print HTTP response and signal that we're done -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_CONNECT) { // Connected to server. Extract host name from URL struct mg_str host = mg_url_host(s_url); @@ -40,7 +40,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { data[1] += c->recv.len; fwrite(c->recv.buf, 1, c->recv.len, stdout); c->recv.len = 0; // And cleanup the receive buffer. Streming! - if (data[1] >= data[0]) * (bool *) fn_data = true; + if (data[1] >= data[0]) * (bool *) c->fn_data = true; } else { struct mg_http_message hm; int n = mg_http_parse((char *) c->recv.buf, c->recv.len, &hm); @@ -50,13 +50,13 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { data[0] = n + hm.body.len; data[1] = c->recv.len; c->recv.len = 0; // Cleanup receive buffer - if (data[1] >= data[0]) * (bool *) fn_data = true; + if (data[1] >= data[0]) * (bool *) c->fn_data = true; } } } else if (ev == MG_EV_CLOSE) { - *(bool *) fn_data = true; // tell event loop to stop + *(bool *) c->fn_data = true; // tell event loop to stop } else if (ev == MG_EV_ERROR) { - *(bool *) fn_data = true; // Error, tell event loop to stop + *(bool *) c->fn_data = true; // Error, tell event loop to stop } (void) ev_data; } diff --git a/examples/huge-response/main.c b/examples/huge-response/main.c index 209face5..3cc164fc 100644 --- a/examples/huge-response/main.c +++ b/examples/huge-response/main.c @@ -41,7 +41,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) { return n; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = ev_data; if (mg_http_match_uri(hm, "/api/data")) { @@ -66,7 +66,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, hm, &opts); } } - (void) fn_data; } static void timer_fn(void *arg) { diff --git a/examples/json-rpc-over-websocket/main.c b/examples/json-rpc-over-websocket/main.c index 308aa397..2a4ce3aa 100644 --- a/examples/json-rpc-over-websocket/main.c +++ b/examples/json-rpc-over-websocket/main.c @@ -26,7 +26,7 @@ static void rpc_mul(struct mg_rpc_req *r) { // This RESTful server implements the following endpoints: // /websocket - upgrade to Websocket, and implement websocket echo server // any other URI serves static files from s_web_root -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_WS_OPEN) { @@ -51,7 +51,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (io.buf) mg_ws_send(c, (char *) io.buf, io.len, WEBSOCKET_OP_TEXT); mg_iobuf_free(&io); } - (void) fn_data; } static void timer_fn(void *arg) { diff --git a/examples/live-log/main.c b/examples/live-log/main.c index b4b198b2..204e0c85 100644 --- a/examples/live-log/main.c +++ b/examples/live-log/main.c @@ -7,7 +7,7 @@ // /api/log/static - returns contents of log.txt file // /api/log/live - hangs forever, and returns live log messages // all other URI - serves web_root/ directory -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/log/static")) { @@ -21,7 +21,6 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } static void log_message(const char *filename, const char *message) { diff --git a/examples/microchip/same54-xpro/mqtt-client/main.c b/examples/microchip/same54-xpro/mqtt-client/main.c index 0988574a..8656f4d4 100644 --- a/examples/microchip/same54-xpro/mqtt-client/main.c +++ b/examples/microchip/same54-xpro/mqtt-client/main.c @@ -31,7 +31,7 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG } } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { MG_INFO(("%lu CREATED", c->id)); // c->is_hexdumping = 1; @@ -66,7 +66,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_INFO(("%lu CLOSED", c->id)); s_conn = NULL; // Mark that we're closed } - (void) fn_data; } // Timer function - recreate client connection if it is closed diff --git a/examples/micropython/mongoose/main.c b/examples/micropython/mongoose/main.c index c600b2ab..c3c413f4 100644 --- a/examples/micropython/mongoose/main.c +++ b/examples/micropython/mongoose/main.c @@ -8,9 +8,8 @@ static void t_fn(void *arg) { // Tick periodically (void) arg; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) mg_http_reply(c, 200, "", "hi\n"); - (void) fn_data; (void) ev_data; } diff --git a/examples/mip-pcap/main.c b/examples/mip-pcap/main.c index 81935ad4..87b5679b 100644 --- a/examples/mip-pcap/main.c +++ b/examples/mip-pcap/main.c @@ -42,20 +42,20 @@ static size_t pcap_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) { return received; } -static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn2(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; MG_DEBUG(("Got response (%d) %.*s...", (int) hm->message.len, 12, hm->message.ptr)); c->is_draining = 1; } else if (ev == MG_EV_CONNECT) { - mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) fn_data)); + mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) c->fn_data)); } else if (ev == MG_EV_CLOSE) { - free(fn_data); + free(c->fn_data); } } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/debug")) { @@ -75,7 +75,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { hm->message.ptr); } } - (void) ev_data, (void) fn_data; + (void) ev_data; } int main(int argc, char *argv[]) { diff --git a/examples/modbus-dashboard/net.c b/examples/modbus-dashboard/net.c index d261708f..aef60afd 100644 --- a/examples/modbus-dashboard/net.c +++ b/examples/modbus-dashboard/net.c @@ -40,7 +40,7 @@ uint64_t mg_now(void) { // SNTP connection event handler. When we get a response from an SNTP server, // adjust s_boot_timestamp. We'll get a valid time from that point on -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { uint64_t *expiration_time = (uint64_t *) c->data; if (ev == MG_EV_OPEN) { *expiration_time = mg_millis() + 3000; // Store expiration time in 3s @@ -51,7 +51,6 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_POLL) { if (mg_millis() > *expiration_time) c->is_closing = 1; } - (void) fn_data; } // SNTP timer function. Sync up time @@ -99,7 +98,7 @@ static void handle_settings_get(struct mg_connection *c) { } // Modbus handler function -static void mfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void mfn(struct mg_connection *c, int ev, void *ev_data) { struct conndata *cd = (struct conndata *) c->data; if (ev == MG_EV_READ) { MG_INFO(("%lu RECEIVED %lu", c->id, c->recv.len)); @@ -117,7 +116,7 @@ static void mfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { c->is_closing = 1; } } - (void) ev_data, (void) fn_data; + (void) ev_data; } static void send8(struct mg_connection *c, uint8_t val) { @@ -242,10 +241,10 @@ static size_t print_mb_resp(void (*out)(char, void *), void *ptr, va_list *ap) { } // HTTP request handler function -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { struct conndata *cd = (struct conndata *) c->data; if (ev == MG_EV_ACCEPT) { - if (fn_data != NULL) { // TLS listener! + if (c->fn_data != NULL) { // TLS listener! struct mg_tls_opts opts = {0}; opts.cert = mg_unpacked("/certs/server_cert.pem"); opts.key = mg_unpacked("/certs/server_key.pem"); diff --git a/examples/modbus-dashboard/web_root/main.css b/examples/modbus-dashboard/web_root/main.css index 8a757d00..f5b15ec3 100644 --- a/examples/modbus-dashboard/web_root/main.css +++ b/examples/modbus-dashboard/web_root/main.css @@ -1 +1 @@ -/*! tailwindcss v3.3.2 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:Inter var,Helvetica,sans-serif;font-feature-settings:"cv11","ss01";font-variation-settings:"opsz" 32}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.pointer-events-auto{pointer-events:auto}.fixed{position:fixed}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.inset-0{inset:0}.bottom-0{bottom:0}.left-0{left:0}.right-auto{right:auto}.top-0{top:0}.z-10{z-index:10}.z-\[48\]{z-index:48}.z-\[60\]{z-index:60}.m-4{margin:1rem}.my-0{margin-top:0;margin-bottom:0}.my-1{margin-top:.25rem;margin-bottom:.25rem}.my-2{margin-top:.5rem;margin-bottom:.5rem}.mb-1{margin-bottom:.25rem}.ml-3{margin-left:.75rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-1{margin-top:.25rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:.75rem}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.hidden{display:none}.h-10{height:2.5rem}.h-12{height:3rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-full{height:100%}.max-h-64{max-height:16rem}.min-h-screen{min-height:100vh}.w-0{width:0}.w-11{width:2.75rem}.w-4{width:1rem}.w-5{width:1.25rem}.w-6{width:1.5rem}.w-72{width:18rem}.w-full{width:100%}.max-w-sm{max-width:24rem}.flex-1{flex:1 1 0%}.flex-shrink-0,.shrink-0{flex-shrink:0}.grow-0{flex-grow:0}.basis-\[30px\]{flex-basis:30px}.-translate-x-full{--tw-translate-x:-100%}.-translate-x-full,.translate-x-0{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-0{--tw-translate-x:0px}.translate-x-5{--tw-translate-x:1.25rem}.translate-x-5,.translate-y-0{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-y-0{--tw-translate-y:0px}.translate-y-2{--tw-translate-y:0.5rem}.transform,.translate-y-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.place-content-end{place-content:end}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-center{align-items:center}.justify-center{justify-content:center}.gap-2{gap:.5rem}.gap-4{gap:1rem}.gap-x-3{-moz-column-gap:.75rem;column-gap:.75rem}.gap-x-4{-moz-column-gap:1rem;column-gap:1rem}.gap-y-6{row-gap:1.5rem}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.self-start{align-self:flex-start}.self-stretch{align-self:stretch}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-scroll{overflow:scroll}.overflow-y-auto{overflow-y:auto}.truncate{overflow:hidden;white-space:nowrap}.text-ellipsis,.truncate{text-overflow:ellipsis}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity))}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity))}.border-transparent{border-color:#0000}.bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity))}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity))}.bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.bg-slate-50{--tw-bg-opacity:1;background-color:rgb(248 250 252/var(--tw-bg-opacity))}.bg-violet-100{--tw-bg-opacity:1;background-color:rgb(237 233 254/var(--tw-bg-opacity))}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-4{padding:1rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.py-0{padding-top:0;padding-bottom:0}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pl-72{padding-left:18rem}.pt-0{padding-top:0}.pt-0\.5{padding-top:.125rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-light{font-weight:300}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.leading-6{line-height:1.5rem}.text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity))}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.text-green-400{--tw-text-opacity:1;color:rgb(74 222 128/var(--tw-text-opacity))}.text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity))}.text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity))}.text-slate-400{--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity))}.text-slate-500{--tw-text-opacity:1;color:rgb(100 116 139/var(--tw-text-opacity))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 #0000001a,0 1px 2px -1px #0000001a;--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.shadow,.shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a;--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.shadow-sm{--tw-shadow:0 1px 2px 0 #0000000d;--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.ring-0{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-0,.ring-1{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-black{--tw-ring-opacity:1;--tw-ring-color:rgb(0 0 0/var(--tw-ring-opacity))}.ring-opacity-5{--tw-ring-opacity:0.05}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}.duration-300{transition-duration:.3s}.ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}.ease-out{transition-timing-function:cubic-bezier(0,0,.2,1)}.placeholder\:text-gray-400::-moz-placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.placeholder\:text-gray-400::placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.hover\:bg-blue-500:hover{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity))}.hover\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity))}.hover\:text-blue-600:hover{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity))}.hover\:text-gray-500:hover{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.focus\:outline-none:focus{outline:2px solid #0000;outline-offset:2px}.focus\:ring-0:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-blue-400:disabled{--tw-bg-opacity:1;background-color:rgb(96 165 250/var(--tw-bg-opacity))}.disabled\:bg-gray-100:disabled{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.disabled\:text-gray-500:disabled{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}@media (min-width:640px){.sm\:translate-x-0{--tw-translate-x:0px}.sm\:translate-x-0,.sm\:translate-x-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:translate-x-2{--tw-translate-x:0.5rem}.sm\:translate-y-0{--tw-translate-y:0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:items-start{align-items:flex-start}.sm\:items-end{align-items:flex-end}.sm\:p-6{padding:1.5rem}}@media (min-width:768px){.md\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){.lg\:block{display:block}.lg\:h-4{height:1rem}.lg\:w-px{width:1px}.lg\:gap-x-6{-moz-column-gap:1.5rem;column-gap:1.5rem}.lg\:bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}} \ No newline at end of file +/*! tailwindcss v3.3.5 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:Inter var,Helvetica,sans-serif;font-feature-settings:"cv11","ss01";font-variation-settings:"opsz" 32}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}.pointer-events-none{pointer-events:none}.pointer-events-auto{pointer-events:auto}.fixed{position:fixed}.absolute{position:absolute}.relative{position:relative}.sticky{position:sticky}.inset-0{inset:0}.bottom-0{bottom:0}.left-0{left:0}.right-auto{right:auto}.top-0{top:0}.z-10{z-index:10}.z-\[48\]{z-index:48}.z-\[60\]{z-index:60}.m-4{margin:1rem}.my-0{margin-top:0;margin-bottom:0}.my-1{margin-top:.25rem;margin-bottom:.25rem}.my-2{margin-top:.5rem;margin-bottom:.5rem}.mb-1{margin-bottom:.25rem}.ml-3{margin-left:.75rem}.ml-4{margin-left:1rem}.mr-2{margin-right:.5rem}.mt-1{margin-top:.25rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:.75rem}.inline-block{display:inline-block}.flex{display:flex}.inline-flex{display:inline-flex}.grid{display:grid}.hidden{display:none}.h-10{height:2.5rem}.h-12{height:3rem}.h-5{height:1.25rem}.h-6{height:1.5rem}.h-full{height:100%}.max-h-64{max-height:16rem}.min-h-screen{min-height:100vh}.w-0{width:0}.w-11{width:2.75rem}.w-4{width:1rem}.w-5{width:1.25rem}.w-6{width:1.5rem}.w-72{width:18rem}.w-full{width:100%}.max-w-sm{max-width:24rem}.flex-1{flex:1 1 0%}.flex-shrink-0,.shrink-0{flex-shrink:0}.grow-0{flex-grow:0}.basis-\[30px\]{flex-basis:30px}.-translate-x-full{--tw-translate-x:-100%}.-translate-x-full,.translate-x-0{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-x-0{--tw-translate-x:0px}.translate-x-5{--tw-translate-x:1.25rem}.translate-x-5,.translate-y-0{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.translate-y-0{--tw-translate-y:0px}.translate-y-2{--tw-translate-y:0.5rem}.transform,.translate-y-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@keyframes spin{to{transform:rotate(1turn)}}.animate-spin{animation:spin 1s linear infinite}.cursor-pointer{cursor:pointer}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.flex-col{flex-direction:column}.place-content-end{place-content:end}.items-start{align-items:flex-start}.items-end{align-items:flex-end}.items-center{align-items:center}.justify-center{justify-content:center}.gap-2{gap:.5rem}.gap-4{gap:1rem}.gap-x-3{-moz-column-gap:.75rem;column-gap:.75rem}.gap-x-4{-moz-column-gap:1rem;column-gap:1rem}.gap-y-6{row-gap:1.5rem}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.divide-y>:not([hidden])~:not([hidden]){--tw-divide-y-reverse:0;border-top-width:calc(1px*(1 - var(--tw-divide-y-reverse)));border-bottom-width:calc(1px*var(--tw-divide-y-reverse))}.self-start{align-self:flex-start}.self-stretch{align-self:stretch}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-scroll{overflow:scroll}.overflow-y-auto{overflow-y:auto}.truncate{overflow:hidden;white-space:nowrap}.text-ellipsis,.truncate{text-overflow:ellipsis}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.rounded-lg{border-radius:.5rem}.rounded-md{border-radius:.375rem}.border{border-width:1px}.border-2{border-width:2px}.border-b{border-bottom-width:1px}.border-l{border-left-width:1px}.border-r{border-right-width:1px}.border-gray-200{--tw-border-opacity:1;border-color:rgb(229 231 235/var(--tw-border-opacity))}.border-gray-300{--tw-border-opacity:1;border-color:rgb(209 213 219/var(--tw-border-opacity))}.border-red-200{--tw-border-opacity:1;border-color:rgb(254 202 202/var(--tw-border-opacity))}.border-transparent{border-color:#0000}.bg-blue-600{--tw-bg-opacity:1;background-color:rgb(37 99 235/var(--tw-bg-opacity))}.bg-gray-100{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}.bg-red-100{--tw-bg-opacity:1;background-color:rgb(254 226 226/var(--tw-bg-opacity))}.bg-slate-100{--tw-bg-opacity:1;background-color:rgb(241 245 249/var(--tw-bg-opacity))}.bg-slate-50{--tw-bg-opacity:1;background-color:rgb(248 250 252/var(--tw-bg-opacity))}.bg-violet-100{--tw-bg-opacity:1;background-color:rgb(237 233 254/var(--tw-bg-opacity))}.bg-white{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity))}.p-2{padding:.5rem}.p-4{padding:1rem}.px-1{padding-left:.25rem;padding-right:.25rem}.px-2{padding-left:.5rem;padding-right:.5rem}.px-2\.5{padding-left:.625rem;padding-right:.625rem}.px-4{padding-left:1rem;padding-right:1rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.py-0{padding-top:0;padding-bottom:0}.py-0\.5{padding-top:.125rem;padding-bottom:.125rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-6{padding-top:1.5rem;padding-bottom:1.5rem}.pl-72{padding-left:18rem}.pt-0{padding-top:0}.pt-0\.5{padding-top:.125rem}.text-sm{font-size:.875rem;line-height:1.25rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.text-xs{font-size:.75rem;line-height:1rem}.font-bold{font-weight:700}.font-light{font-weight:300}.font-medium{font-weight:500}.font-normal{font-weight:400}.font-semibold{font-weight:600}.uppercase{text-transform:uppercase}.leading-6{line-height:1.5rem}.text-blue-600{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity))}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.text-gray-500{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.text-gray-600{--tw-text-opacity:1;color:rgb(75 85 99/var(--tw-text-opacity))}.text-gray-700{--tw-text-opacity:1;color:rgb(55 65 81/var(--tw-text-opacity))}.text-gray-900{--tw-text-opacity:1;color:rgb(17 24 39/var(--tw-text-opacity))}.text-green-400{--tw-text-opacity:1;color:rgb(74 222 128/var(--tw-text-opacity))}.text-green-600{--tw-text-opacity:1;color:rgb(22 163 74/var(--tw-text-opacity))}.text-red-400{--tw-text-opacity:1;color:rgb(248 113 113/var(--tw-text-opacity))}.text-slate-400{--tw-text-opacity:1;color:rgb(148 163 184/var(--tw-text-opacity))}.text-slate-500{--tw-text-opacity:1;color:rgb(100 116 139/var(--tw-text-opacity))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.opacity-0{opacity:0}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 #0000001a,0 1px 2px -1px #0000001a;--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color)}.shadow,.shadow-lg{box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a;--tw-shadow-colored:0 10px 15px -3px var(--tw-shadow-color),0 4px 6px -4px var(--tw-shadow-color)}.shadow-sm{--tw-shadow:0 1px 2px 0 #0000000d;--tw-shadow-colored:0 1px 2px 0 var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.ring-0{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-0,.ring-1{box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.ring-1{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)}.ring-black{--tw-ring-opacity:1;--tw-ring-color:rgb(0 0 0/var(--tw-ring-opacity))}.ring-opacity-5{--tw-ring-opacity:0.05}.filter{filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-all{transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.duration-200{transition-duration:.2s}.duration-300{transition-duration:.3s}.ease-in-out{transition-timing-function:cubic-bezier(.4,0,.2,1)}.ease-out{transition-timing-function:cubic-bezier(0,0,.2,1)}.placeholder\:text-gray-400::-moz-placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.placeholder\:text-gray-400::placeholder{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.hover\:bg-blue-500:hover{--tw-bg-opacity:1;background-color:rgb(59 130 246/var(--tw-bg-opacity))}.hover\:bg-gray-50:hover{--tw-bg-opacity:1;background-color:rgb(249 250 251/var(--tw-bg-opacity))}.hover\:text-blue-600:hover{--tw-text-opacity:1;color:rgb(37 99 235/var(--tw-text-opacity))}.hover\:text-gray-500:hover{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}.focus\:outline-none:focus{outline:2px solid #0000;outline-offset:2px}.focus\:ring-0:focus{--tw-ring-offset-shadow:var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow:var(--tw-ring-inset) 0 0 0 calc(var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow,0 0 #0000)}.disabled\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\:bg-blue-400:disabled{--tw-bg-opacity:1;background-color:rgb(96 165 250/var(--tw-bg-opacity))}.disabled\:bg-gray-100:disabled{--tw-bg-opacity:1;background-color:rgb(243 244 246/var(--tw-bg-opacity))}.disabled\:text-gray-500:disabled{--tw-text-opacity:1;color:rgb(107 114 128/var(--tw-text-opacity))}@media (min-width:640px){.sm\:translate-x-0{--tw-translate-x:0px}.sm\:translate-x-0,.sm\:translate-x-2{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:translate-x-2{--tw-translate-x:0.5rem}.sm\:translate-y-0{--tw-translate-y:0px;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.sm\:items-start{align-items:flex-start}.sm\:items-end{align-items:flex-end}.sm\:p-6{padding:1.5rem}}@media (min-width:768px){.md\:grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.md\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}}@media (min-width:1024px){.lg\:block{display:block}.lg\:h-4{height:1rem}.lg\:w-px{width:1px}.lg\:gap-x-6{-moz-column-gap:1.5rem;column-gap:1.5rem}.lg\:bg-gray-200{--tw-bg-opacity:1;background-color:rgb(229 231 235/var(--tw-bg-opacity))}} \ No newline at end of file diff --git a/examples/mqtt-client-aws-iot/main.c b/examples/mqtt-client-aws-iot/main.c index 808c6445..62f4b85c 100644 --- a/examples/mqtt-client-aws-iot/main.c +++ b/examples/mqtt-client-aws-iot/main.c @@ -38,7 +38,7 @@ static int s_qos = 1; #include "mongoose.h" -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_CONNECT) { @@ -84,7 +84,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) { MG_INFO(("Got event %d, stopping...", ev)); - *(bool *) fn_data = true; // Signal that we're done + *(bool *) c->fn_data = true; // Signal that we're done } } diff --git a/examples/mqtt-client/main.c b/examples/mqtt-client/main.c index c715de98..1012ca4f 100644 --- a/examples/mqtt-client/main.c +++ b/examples/mqtt-client/main.c @@ -24,7 +24,7 @@ static void signal_handler(int signo) { s_signo = signo; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { MG_INFO(("%lu CREATED", c->id)); // c->is_hexdumping = 1; @@ -65,7 +65,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_INFO(("%lu CLOSED", c->id)); s_conn = NULL; // Mark that we're closed } - (void) fn_data; } // Timer function - recreate client connection if it is closed diff --git a/examples/mqtt-dashboard/device/net.c b/examples/mqtt-dashboard/device/net.c index f86bbcd9..2fec222b 100644 --- a/examples/mqtt-dashboard/device/net.c +++ b/examples/mqtt-dashboard/device/net.c @@ -190,7 +190,7 @@ static void rpc_ota_upload(struct mg_rpc_req *r) { } } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { MG_INFO(("%lu CREATED", c->id)); // c->is_hexdumping = 1; @@ -223,7 +223,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_INFO(("%lu CLOSED", c->id)); s_conn = NULL; // Mark that we're closed } - (void) fn_data; } // Timer function - recreate client connection if it is closed diff --git a/examples/mqtt-over-ws-client/main.c b/examples/mqtt-over-ws-client/main.c index c9d0008b..74d2633b 100644 --- a/examples/mqtt-over-ws-client/main.c +++ b/examples/mqtt-over-ws-client/main.c @@ -20,7 +20,7 @@ static const char *s_url = static const char *s_topic = "mg/test"; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ERROR) { // On error, log error message MG_ERROR(("%p %s", c->fd, (char *) ev_data)); @@ -89,7 +89,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) { - *(bool *) fn_data = true; // Signal that we're done + *(bool *) c->fn_data = true; // Signal that we're done } } diff --git a/examples/mqtt-server/main.c b/examples/mqtt-server/main.c index 0b96ece4..77835e5f 100644 --- a/examples/mqtt-server/main.c +++ b/examples/mqtt-server/main.c @@ -53,7 +53,7 @@ size_t mg_mqtt_next_unsub(struct mg_mqtt_message *msg, struct mg_str *topic, } // Event handler function -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_MQTT_CMD) { struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; MG_DEBUG(("cmd %d qos %d", mm->cmd, mm->qos)); @@ -131,7 +131,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { LIST_DELETE(struct sub, &s_subs, sub); } } - (void) fn_data; } int main(void) { diff --git a/examples/multi-threaded-12m/main.c b/examples/multi-threaded-12m/main.c index 64f49c1f..63bdcf52 100644 --- a/examples/multi-threaded-12m/main.c +++ b/examples/multi-threaded-12m/main.c @@ -43,7 +43,7 @@ static void *thread_function(void *param) { } // HTTP request callback -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN && c->is_listening) { // Start worker thread struct thread_data *data = calloc(1, sizeof(*data)); // Worker owns it @@ -75,7 +75,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_ws_send(wc, data->ptr, data->len, WEBSOCKET_OP_TEXT); } } - (void) fn_data; } int main(void) { diff --git a/examples/multi-threaded/main.c b/examples/multi-threaded/main.c index 83ba42d0..b220cfa5 100644 --- a/examples/multi-threaded/main.c +++ b/examples/multi-threaded/main.c @@ -39,7 +39,7 @@ static void *thread_function(void *param) { } // HTTP request callback -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/fast")) { @@ -58,7 +58,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { struct mg_str *data = (struct mg_str *) ev_data; mg_http_reply(c, 200, "", "Result: %.*s\n", data->len, data->ptr); } - (void) fn_data; } int main(void) { diff --git a/examples/nxp/rt1020-evk-make-baremetal-builtin/main.c b/examples/nxp/rt1020-evk-make-baremetal-builtin/main.c index e41e5cd0..e44b248c 100644 --- a/examples/nxp/rt1020-evk-make-baremetal-builtin/main.c +++ b/examples/nxp/rt1020-evk-make-baremetal-builtin/main.c @@ -32,8 +32,8 @@ static void timer_fn(void *arg) { } #ifndef RUNINFLASH -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/hello")) { // Request to /api/hello diff --git a/examples/nxp/rt1020-evk-make-freertos-builtin/main.c b/examples/nxp/rt1020-evk-make-freertos-builtin/main.c index 0cf3bd02..ea7bd3a3 100644 --- a/examples/nxp/rt1020-evk-make-freertos-builtin/main.c +++ b/examples/nxp/rt1020-evk-make-freertos-builtin/main.c @@ -21,8 +21,8 @@ static void timer_fn(void *arg) { ifp->ndrop, ifp->nerr)); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/hello")) { // Request to /api/hello diff --git a/examples/rp2040/pico-rmii/main.c b/examples/rp2040/pico-rmii/main.c index 3c2ed5a3..f41eb814 100644 --- a/examples/rp2040/pico-rmii/main.c +++ b/examples/rp2040/pico-rmii/main.c @@ -10,7 +10,7 @@ #define CLKREFPIN 20 // either 20 or 22 -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { mg_http_reply(c, 200, "", "ok\n"); } diff --git a/examples/smtp-client/main.c b/examples/smtp-client/main.c index fa7e7354..4c2f34ac 100644 --- a/examples/smtp-client/main.c +++ b/examples/smtp-client/main.c @@ -13,7 +13,7 @@ static bool s_quit; enum { EHLO, STARTTLS, STARTTLS_WAIT, AUTH, FROM, TO, DATA, BODY, QUIT, END }; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { uint8_t *state = (uint8_t *) c->data; if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; @@ -69,7 +69,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_INFO(("TLS handshake done! Sending EHLO again")); mg_printf(c, "EHLO myname\r\n"); } - (void) fn_data, (void) ev_data; + (void) ev_data; } int main(void) { diff --git a/examples/sntp-time-sync/main.c b/examples/sntp-time-sync/main.c index 8e89e8d2..27801ac0 100644 --- a/examples/sntp-time-sync/main.c +++ b/examples/sntp-time-sync/main.c @@ -23,7 +23,7 @@ time_t my_time(time_t *tp) { } // SNTP client callback -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { int64_t t = *(int64_t *) ev_data; MG_INFO(("Got SNTP time: %lld ms from epoch", t)); @@ -31,7 +31,7 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_CLOSE) { s_sntp_conn = NULL; } - (void) fn_data, (void) c; + (void) c; } // Called every 5 seconds. Increase that for production case. diff --git a/examples/socks5-server/main.c b/examples/socks5-server/main.c index bcdc862d..f673147a 100644 --- a/examples/socks5-server/main.c +++ b/examples/socks5-server/main.c @@ -79,14 +79,13 @@ static void exchange(struct mg_connection *c) { } } -static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn2(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { exchange(c); } else if (ev == MG_EV_CLOSE) { disband(c); } (void) ev_data; - (void) fn_data; } // Request, https://www.ietf.org/rfc/rfc1928.txt paragraph 4 @@ -149,7 +148,7 @@ static void request(struct mg_connection *c) { c->data[0] = STATE_ESTABLISHED; // Mark ourselves as connected } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { // We use the first label byte as a state if (c->data[0] == STATE_HANDSHAKE) handshake(c); @@ -158,7 +157,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_CLOSE) { disband(c); } - (void) fn_data; (void) ev_data; } diff --git a/examples/stm32/nucleo-f429zi-make-baremetal-builtin-rndis/main.c b/examples/stm32/nucleo-f429zi-make-baremetal-builtin-rndis/main.c index 228c90e3..dce94871 100644 --- a/examples/stm32/nucleo-f429zi-make-baremetal-builtin-rndis/main.c +++ b/examples/stm32/nucleo-f429zi-make-baremetal-builtin-rndis/main.c @@ -63,7 +63,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) { return tud_inited() && tud_ready() && tud_connected(); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/debug")) { @@ -74,7 +74,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_reply(c, 200, "", "hi\n"); } } - (void) fn_data; } int main(void) { diff --git a/examples/stm32/nucleo-f746zg-make-baremetal-builtin-rndis/main.c b/examples/stm32/nucleo-f746zg-make-baremetal-builtin-rndis/main.c index 228c90e3..dce94871 100644 --- a/examples/stm32/nucleo-f746zg-make-baremetal-builtin-rndis/main.c +++ b/examples/stm32/nucleo-f746zg-make-baremetal-builtin-rndis/main.c @@ -63,7 +63,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) { return tud_inited() && tud_ready() && tud_connected(); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/debug")) { @@ -74,7 +74,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_reply(c, 200, "", "hi\n"); } } - (void) fn_data; } int main(void) { diff --git a/examples/stm32/nucleo-g031-make-baremetal-builtin/main.c b/examples/stm32/nucleo-g031-make-baremetal-builtin/main.c index 4a0292b9..7a4be44c 100644 --- a/examples/stm32/nucleo-g031-make-baremetal-builtin/main.c +++ b/examples/stm32/nucleo-g031-make-baremetal-builtin/main.c @@ -42,8 +42,8 @@ static void timer_fn(void *arg) { ifp->nerr)); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/hello")) { // Request to /api/hello diff --git a/examples/tcp/main.c b/examples/tcp/main.c index e5175288..58938f64 100644 --- a/examples/tcp/main.c +++ b/examples/tcp/main.c @@ -13,8 +13,8 @@ static struct c_res_s { } c_res; // CLIENT event handler -static void cfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - int *i = &((struct c_res_s *) fn_data)->i; +static void cfn(struct mg_connection *c, int ev, void *ev_data) { + int *i = &((struct c_res_s *) c->fn_data)->i; if (ev == MG_EV_OPEN) { MG_INFO(("CLIENT has been initialized")); } else if (ev == MG_EV_CONNECT) { @@ -33,7 +33,7 @@ static void cfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_CLOSE) { MG_INFO(("CLIENT disconnected")); // signal we are done - ((struct c_res_s *) fn_data)->c = NULL; + ((struct c_res_s *) c->fn_data)->c = NULL; } else if (ev == MG_EV_ERROR) { MG_INFO(("CLIENT error: %s", (char *) ev_data)); } else if (ev == MG_EV_POLL && *i != 0) { @@ -51,7 +51,7 @@ static void cfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } // SERVER event handler -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN && c->is_listening == 1) { MG_INFO(("SERVER is listening")); } else if (ev == MG_EV_ACCEPT) { @@ -72,7 +72,6 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_ERROR) { MG_INFO(("SERVER error: %s", (char *) ev_data)); } - (void) fn_data; } // Timer function - recreate client connection if it is closed diff --git a/examples/ti/ek-tm4c1294xl-make-baremetal-builtin-rndis/main.c b/examples/ti/ek-tm4c1294xl-make-baremetal-builtin-rndis/main.c index c8ce33e3..750f4831 100644 --- a/examples/ti/ek-tm4c1294xl-make-baremetal-builtin-rndis/main.c +++ b/examples/ti/ek-tm4c1294xl-make-baremetal-builtin-rndis/main.c @@ -61,7 +61,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) { return tud_inited() && tud_ready() && tud_connected(); } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/debug")) { @@ -72,7 +72,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_reply(c, 200, "", "hi\n"); } } - (void) fn_data; } int main(void) { diff --git a/examples/timers/main.c b/examples/timers/main.c index 53f2acaa..656427ea 100644 --- a/examples/timers/main.c +++ b/examples/timers/main.c @@ -11,7 +11,7 @@ static const char *s_listen_on = "http://localhost:8000"; static const char *s_web_root = "web_root"; // This RESTful server implements the following endpoints: -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/websocket")) { @@ -28,7 +28,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT); mg_iobuf_del(&c->recv, 0, c->recv.len); } - (void) fn_data; } static void timer_fn(void *arg) { diff --git a/examples/uart-bridge/main.c b/examples/uart-bridge/main.c index 378087d4..fa45c54a 100644 --- a/examples/uart-bridge/main.c +++ b/examples/uart-bridge/main.c @@ -4,7 +4,7 @@ #include "mongoose.h" const char *s_listening_url = "http://0.0.0.0:8000"; -void uart_bridge_fn(struct mg_connection *, int, void *, void *); +void uart_bridge_fn(struct mg_connection *, int, void *); int main(void) { struct mg_mgr mgr; diff --git a/examples/uart-bridge/net.c b/examples/uart-bridge/net.c index 91b7aecc..4984d8a9 100644 --- a/examples/uart-bridge/net.c +++ b/examples/uart-bridge/net.c @@ -64,24 +64,23 @@ void config_write(struct mg_str config) { #endif // Event handler for a connected Websocket client -static void ws_fn(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void ws_fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { - mg_ws_upgrade(c, evd, NULL); + mg_ws_upgrade(c, ev_data, NULL); } else if (ev == MG_EV_WS_OPEN) { // c->is_hexdumping = 1; c->data[0] = 'W'; // When WS handhake is done, mark us as WS client } else if (ev == MG_EV_WS_MSG) { - struct mg_ws_message *wm = (struct mg_ws_message *) evd; + struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; uart_write(wm->data.ptr, wm->data.len); // Send to UART c->recv.len = 0; // Discard received data } else if (ev == MG_EV_CLOSE) { if (c->is_listening) s_state.websocket.c = NULL; } - (void) fnd; } // Event handler for a connected TCP client -static void tcp_fn(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void tcp_fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ACCEPT) { // c->is_hexdumping = 1; c->data[0] = 'T'; // When client is connected, mark us as TCP client @@ -91,7 +90,7 @@ static void tcp_fn(struct mg_connection *c, int ev, void *evd, void *fnd) { } else if (ev == MG_EV_CLOSE) { if (c->is_listening) s_state.tcp.c = NULL; } - (void) fnd, (void) evd; + (void) ev_data; } // Extract topic name from the MQTT address @@ -102,7 +101,7 @@ static struct mg_str mqtt_topic(const char *name, const char *dflt) { } // Event handler for MQTT connection -static void mq_fn(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void mq_fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_MQTT_OPEN) { @@ -113,12 +112,11 @@ static void mq_fn(struct mg_connection *c, int ev, void *evd, void *fnd) { sub_opts.qos = 1; mg_mqtt_sub(c, &sub_opts); // Subscribe to RX topic } else if (ev == MG_EV_MQTT_MSG) { - struct mg_mqtt_message *mm = evd; // MQTT message + struct mg_mqtt_message *mm = ev_data; // MQTT message uart_write(mm->data.ptr, mm->data.len); // Send to UART } else if (ev == MG_EV_CLOSE) { s_state.mqtt.c = NULL; } - (void) fnd, (void) evd; } // Software timer with a frequency close to the scheduling time slot diff --git a/examples/udp-ssdp-search/main.c b/examples/udp-ssdp-search/main.c index 4315ddab..70e0c293 100644 --- a/examples/udp-ssdp-search/main.c +++ b/examples/udp-ssdp-search/main.c @@ -5,8 +5,8 @@ static const char *s_ssdp_url = "udp://239.255.255.250:1900"; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - MG_DEBUG(("%p got event: %d %p %p", c, ev, ev_data, fn_data)); +static void fn(struct mg_connection *c, int ev, void *ev_data) { + MG_DEBUG(("%p got event: %d %p", c, ev, ev_data)); if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_RESOLVE) { diff --git a/examples/video-stream/main.c b/examples/video-stream/main.c index 441386c9..5bd731d5 100644 --- a/examples/video-stream/main.c +++ b/examples/video-stream/main.c @@ -6,7 +6,7 @@ // HTTP request handler function. It implements the following endpoints: // /api/video1 - hangs forever, returns MJPEG video stream // all other URI - serves web_root/ directory -static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/video1")) { @@ -22,7 +22,6 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } // The image stream is simulated by sending MJPEG frames specified by the diff --git a/examples/wch/ch32v307-make-baremetal-builtin/main.c b/examples/wch/ch32v307-make-baremetal-builtin/main.c index 981634c5..571744b3 100644 --- a/examples/wch/ch32v307-make-baremetal-builtin/main.c +++ b/examples/wch/ch32v307-make-baremetal-builtin/main.c @@ -59,7 +59,7 @@ void SysTick_Init(void) { } // https://mongoose.ws/documentation/#2-minute-integration-guide -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; mg_http_reply(c, 200, "", "ok %p %p\r\n", hm, fn_data); diff --git a/examples/websocket-client/main.c b/examples/websocket-client/main.c index bc21ea7c..6ef87067 100644 --- a/examples/websocket-client/main.c +++ b/examples/websocket-client/main.c @@ -10,7 +10,7 @@ static const char *s_url = "ws://localhost:8000/websocket"; // Print websocket response and signal that we're done -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { c->is_hexdumping = 1; } else if (ev == MG_EV_ERROR) { @@ -26,7 +26,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE || ev == MG_EV_WS_MSG) { - *(bool *) fn_data = true; // Signal that we're done + *(bool *) c->fn_data = true; // Signal that we're done } } diff --git a/examples/websocket-server/main.c b/examples/websocket-server/main.c index cacd2662..3c96c488 100644 --- a/examples/websocket-server/main.c +++ b/examples/websocket-server/main.c @@ -12,7 +12,7 @@ static const char *s_web_root = "."; // /websocket - upgrade to Websocket, and implement websocket echo server // /rest - respond with JSON string {"result": 123} // any other URI serves static files from s_web_root -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_HTTP_MSG) { @@ -34,7 +34,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT); } - (void) fn_data; } int main(void) { diff --git a/examples/webui-login/main.c b/examples/webui-login/main.c index 99d50a30..0704fb70 100644 --- a/examples/webui-login/main.c +++ b/examples/webui-login/main.c @@ -43,7 +43,7 @@ static struct user *getuser(struct mg_http_message *hm) { return NULL; } -void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct user *u = getuser(hm); @@ -63,7 +63,6 @@ void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/webui-plain/main.c b/examples/webui-plain/main.c index 96825ad9..c126798e 100644 --- a/examples/webui-plain/main.c +++ b/examples/webui-plain/main.c @@ -29,7 +29,7 @@ static void update_config(struct mg_str json, const char *path, char **value) { } } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN && c->is_listening) { s_config.url = strdup(MQTT_SERVER); s_config.pub = strdup(MQTT_PUBLISH_TOPIC); @@ -52,7 +52,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/webui-push-rest/main.c b/examples/webui-push-rest/main.c index 5c67a2ce..0ef3b731 100644 --- a/examples/webui-push-rest/main.c +++ b/examples/webui-push-rest/main.c @@ -37,7 +37,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) { (void) ap; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = ev_data; if (mg_http_match_uri(hm, "/api/data")) { @@ -58,7 +58,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, hm, &opts); } } - (void) fn_data; } static void timer_fn(void *arg) { diff --git a/examples/webui-push-ws/main.c b/examples/webui-push-ws/main.c index cf6226df..f66fdcdb 100644 --- a/examples/webui-push-ws/main.c +++ b/examples/webui-push-ws/main.c @@ -10,7 +10,7 @@ static const char *s_listen_on = "http://localhost:8000"; static const char *s_web_root = "web_root"; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/watch")) { @@ -21,7 +21,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } // Push to all watchers diff --git a/examples/webui-rest/main.c b/examples/webui-rest/main.c index 155bcf9c..43177703 100644 --- a/examples/webui-rest/main.c +++ b/examples/webui-rest/main.c @@ -13,7 +13,7 @@ static const char *s_http_addr = "http://localhost:8000"; // HTTP port static const char *s_root_dir = "web_root"; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/api/f1")) { @@ -34,7 +34,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, hm, &opts); } } - (void) fn_data; } int main(void) { diff --git a/examples/wifi-router-dashboard/net.c b/examples/wifi-router-dashboard/net.c index d88a574d..7591fcae 100644 --- a/examples/wifi-router-dashboard/net.c +++ b/examples/wifi-router-dashboard/net.c @@ -109,7 +109,7 @@ static int event_next(int no, struct event *e) { // SNTP connection event handler. When we get a response from an SNTP server, // adjust s_boot_timestamp. We'll get a valid time from that point on -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { uint64_t *expiration_time = (uint64_t *) c->data; if (ev == MG_EV_OPEN) { *expiration_time = mg_millis() + 3000; // Store expiration time in 3s @@ -120,7 +120,6 @@ static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_POLL) { if (mg_millis() > *expiration_time) c->is_closing = 1; } - (void) fn_data; } static void timer_sntp_fn(void *param) { // SNTP timer function. Sync up time @@ -271,9 +270,9 @@ static void handle_dhcp_get(struct mg_connection *c) { } // HTTP request handler function -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ACCEPT) { - if (fn_data != NULL) { // TLS + if (c->fn_data != NULL) { // TLS struct mg_tls_opts opts = {0}; opts.cert = mg_str(s_tls_cert); opts.key = mg_str(s_tls_key); @@ -316,7 +315,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { hm->method.ptr, (int) hm->uri.len, hm->uri.ptr, (int) 3, &c->send.buf[9])); } - (void) fn_data; } void web_init(struct mg_mgr *mgr) { diff --git a/examples/zephyr/http-client/src/main.c b/examples/zephyr/http-client/src/main.c index 9f786aac..a2c77df5 100644 --- a/examples/zephyr/http-client/src/main.c +++ b/examples/zephyr/http-client/src/main.c @@ -14,7 +14,7 @@ static int s_connected = 0; static bool done = false; // Print HTTP response and signal that we're done -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // Connection created. Store connect expiration time in c->data *(int64_t *) c->data = mg_millis() + s_timeout_ms; @@ -49,9 +49,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; MG_INFO(("%.*s", (int) hm->message.len, hm->message.ptr)); c->is_draining = 1; // Tell mongoose to close this connection - *(bool *) fn_data = true; // Tell event loop to stop + *(bool *) c->fn_data = true; // Tell event loop to stop } else if (ev == MG_EV_ERROR) { - *(bool *) fn_data = true; // Error, tell event loop to stop + *(bool *) c->fn_data = true; // Error, tell event loop to stop } } @@ -63,7 +63,7 @@ time_t ourtime(time_t *tp) { } // SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { int64_t t = *(int64_t *) ev_data; MG_INFO(("Got SNTP time: %lld ms from epoch", t)); diff --git a/examples/zephyr/http-server/src/main.c b/examples/zephyr/http-server/src/main.c index 6f250f5a..b306fdb0 100644 --- a/examples/zephyr/http-server/src/main.c +++ b/examples/zephyr/http-server/src/main.c @@ -11,8 +11,8 @@ static time_t s_boot_timestamp = 0; static struct mg_connection *s_sntp_conn = NULL; // Event handler for the listening HTTP/HTTPS connection. -static void wcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - if (ev == MG_EV_ACCEPT && fn_data != NULL) { +static void wcb(struct mg_connection *c, int ev, void *ev_data) { + if (ev == MG_EV_ACCEPT && c->fn_data != NULL) { struct mg_tls_opts opts = {.cert = s_ssl_cert, .key = s_ssl_key}; mg_tls_init(c, &opts); } else if (ev == MG_EV_HTTP_MSG) { @@ -49,7 +49,7 @@ time_t ourtime(time_t *tp) { } // SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { int64_t t = *(int64_t *) ev_data; MG_INFO(("Got SNTP time: %lld ms from epoch", t)); diff --git a/examples/zephyr/mqtt-aws-client/src/main.c b/examples/zephyr/mqtt-aws-client/src/main.c index 606b433f..2d88bdeb 100644 --- a/examples/zephyr/mqtt-aws-client/src/main.c +++ b/examples/zephyr/mqtt-aws-client/src/main.c @@ -16,7 +16,7 @@ static const char *s_tx_topic = "d/tx"; static int s_qos = 1; static int s_connected = 0; -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_ERROR) { @@ -67,7 +67,7 @@ time_t ourtime(time_t *tp) { } // SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { int64_t t = *(int64_t *) ev_data; MG_INFO(("Got SNTP time: %lld ms from epoch", t)); diff --git a/examples/zephyr/websocket-server/src/main.c b/examples/zephyr/websocket-server/src/main.c index ee9aa69c..ecf5d0e9 100644 --- a/examples/zephyr/websocket-server/src/main.c +++ b/examples/zephyr/websocket-server/src/main.c @@ -13,10 +13,10 @@ static struct mg_connection *s_sntp_conn = NULL; // This RESTful server implements the following endpoints: // /websocket - upgrade to Websocket, and implement websocket echo server // /api/rest - respond with JSON string {"result": 123} -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_OPEN) { c->is_hexdumping = 1; - } else if (ev == MG_EV_ACCEPT && fn_data != NULL) { + } else if (ev == MG_EV_ACCEPT && c->fn_data != NULL) { struct mg_tls_opts opts = {.cert = s_ssl_cert, .key = s_ssl_key}; mg_tls_init(c, &opts); } else if (ev == MG_EV_HTTP_MSG) { @@ -35,7 +35,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { MG_INFO(("Got wm: %p, data: %p, %d = %*.s", wm, wm->data.ptr, wm->data.len, wm->data.len, wm->data.ptr)); mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_TEXT); } - (void) fn_data; } // example system time()-like function @@ -46,7 +45,7 @@ time_t ourtime(time_t *tp) { } // SNTP callback. Modifies s_boot_timestamp, to make ourtime() correct -static void sfn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void sfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { int64_t t = *(int64_t *) ev_data; MG_INFO(("Got SNTP time: %lld ms from epoch", t)); diff --git a/mongoose.c b/mongoose.c index b892772c..b3d8d1cd 100644 --- a/mongoose.c +++ b/mongoose.c @@ -852,8 +852,7 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) { return true; } -static void dns_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void dns_cb(struct mg_connection *c, int ev, void *ev_data) { struct dns_data *d, *tmp; struct dns_data **head = (struct dns_data **) &c->mgr->active_dns_requests; if (ev == MG_EV_POLL) { @@ -907,7 +906,6 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data, mg_dns_free(head, d); } } - (void) fn_data; } static bool mg_dns_send(struct mg_connection *c, const struct mg_str *name, @@ -1006,8 +1004,8 @@ void mg_call(struct mg_connection *c, int ev, void *ev_data) { // Run user-defined handler first, in order to give it an ability // to intercept processing (e.g. clean input buffer) before the // protocol handler kicks in - if (c->fn != NULL) c->fn(c, ev, ev_data, c->fn_data); - if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); + if (c->fn != NULL) c->fn(c, ev, ev_data); + if (c->pfn != NULL) c->pfn(c, ev, ev_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) { @@ -1018,7 +1016,7 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) { va_end(ap); MG_ERROR(("%lu %ld %s", c->id, c->fd, buf)); c->is_closing = 1; // Set is_closing before sending MG_EV_CALL - mg_call(c, MG_EV_ERROR, buf); // Let user handler to override it + mg_call(c, MG_EV_ERROR, buf); // Let user handler override it } #ifdef MG_ENABLE_LINES @@ -2286,7 +2284,7 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers, c->is_resp = 0; } -static void http_cb(struct mg_connection *, int, void *, void *); +static void http_cb(struct mg_connection *, int, void *); static void restore_http_cb(struct mg_connection *c) { mg_fs_close((struct mg_fd *) c->pfn_data); c->pfn_data = NULL; @@ -2300,10 +2298,9 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) { return buf; } -static void static_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void static_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_WRITE || ev == MG_EV_POLL) { - struct mg_fd *fd = (struct mg_fd *) fn_data; + struct mg_fd *fd = (struct mg_fd *) c->pfn_data; // Read to send IO buffer directly, avoid extra on-stack buffer size_t n, max = MG_IO_SIZE, space; size_t *cl = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) / @@ -2828,7 +2825,7 @@ static int skip_chunk(const char *buf, int len, int *pl, int *dl) { return i + 2 + n + 2; } -static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void http_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { struct mg_http_message hm; size_t ofs = 0; // Parsing offset @@ -2890,10 +2887,10 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { } if (ofs > 0) mg_iobuf_del(&c->recv, 0, ofs); // Delete processed data } - (void) evd, (void) fnd; + (void) ev_data; } -static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { +static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/quit")) { @@ -2908,7 +2905,7 @@ static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { mg_http_reply(c, 200, "", "hi\n"); } } else if (ev == MG_EV_CLOSE) { - if (c->data[0] == 'X') *(bool *) fnd = true; + if (c->data[0] == 'X') *(bool *) c->fn_data = true; } } @@ -4062,7 +4059,8 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version, } if (p > end) return MQTT_MALFORMED; if (version == 5 && p + 2 < end) { - len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size); + len_len = + (uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size); if (!len_len) return MQTT_MALFORMED; m->props_start = (size_t) (p + len_len - buf); p += len_len + m->props_size; @@ -4078,8 +4076,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version, return MQTT_OK; } -static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { for (;;) { uint8_t version = c->is_mqtt5 ? 5 : 4; @@ -4147,7 +4144,6 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, } } (void) ev_data; - (void) fn_data; } void mg_mqtt_ping(struct mg_connection *nc) { @@ -4191,289 +4187,6 @@ struct mg_connection *mg_mqtt_listen(struct mg_mgr *mgr, const char *url, return c; } -#ifdef MG_ENABLE_LINES -#line 1 "src/net.c" -#endif - - - - - - - - - -size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) { - size_t old = c->send.len; - mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap); - return c->send.len - old; -} - -size_t mg_printf(struct mg_connection *c, const char *fmt, ...) { - size_t len = 0; - va_list ap; - va_start(ap, fmt); - len = mg_vprintf(c, fmt, &ap); - va_end(ap); - return len; -} - -static bool mg_atonl(struct mg_str str, struct mg_addr *addr) { - uint32_t localhost = mg_htonl(0x7f000001); - if (mg_vcasecmp(&str, "localhost") != 0) return false; - memcpy(addr->ip, &localhost, sizeof(uint32_t)); - addr->is_ip6 = false; - return true; -} - -static bool mg_atone(struct mg_str str, struct mg_addr *addr) { - if (str.len > 0) return false; - memset(addr->ip, 0, sizeof(addr->ip)); - addr->is_ip6 = false; - return true; -} - -static bool mg_aton4(struct mg_str str, struct mg_addr *addr) { - uint8_t data[4] = {0, 0, 0, 0}; - size_t i, num_dots = 0; - for (i = 0; i < str.len; i++) { - if (str.ptr[i] >= '0' && str.ptr[i] <= '9') { - int octet = data[num_dots] * 10 + (str.ptr[i] - '0'); - if (octet > 255) return false; - data[num_dots] = (uint8_t) octet; - } else if (str.ptr[i] == '.') { - if (num_dots >= 3 || i == 0 || str.ptr[i - 1] == '.') return false; - num_dots++; - } else { - return false; - } - } - if (num_dots != 3 || str.ptr[i - 1] == '.') return false; - memcpy(&addr->ip, data, sizeof(data)); - addr->is_ip6 = false; - return true; -} - -static bool mg_v4mapped(struct mg_str str, struct mg_addr *addr) { - int i; - uint32_t ipv4; - if (str.len < 14) return false; - if (str.ptr[0] != ':' || str.ptr[1] != ':' || str.ptr[6] != ':') return false; - for (i = 2; i < 6; i++) { - if (str.ptr[i] != 'f' && str.ptr[i] != 'F') return false; - } - // struct mg_str s = mg_str_n(&str.ptr[7], str.len - 7); - if (!mg_aton4(mg_str_n(&str.ptr[7], str.len - 7), addr)) return false; - memcpy(&ipv4, addr->ip, sizeof(ipv4)); - memset(addr->ip, 0, sizeof(addr->ip)); - addr->ip[10] = addr->ip[11] = 255; - memcpy(&addr->ip[12], &ipv4, 4); - addr->is_ip6 = true; - return true; -} - -static bool mg_aton6(struct mg_str str, struct mg_addr *addr) { - size_t i, j = 0, n = 0, dc = 42; - addr->scope_id = 0; - if (str.len > 2 && str.ptr[0] == '[') str.ptr++, str.len -= 2; - if (mg_v4mapped(str, addr)) return true; - for (i = 0; i < str.len; i++) { - if ((str.ptr[i] >= '0' && str.ptr[i] <= '9') || - (str.ptr[i] >= 'a' && str.ptr[i] <= 'f') || - (str.ptr[i] >= 'A' && str.ptr[i] <= 'F')) { - unsigned long val; - if (i > j + 3) return false; - // MG_DEBUG(("%lu %lu [%.*s]", i, j, (int) (i - j + 1), &str.ptr[j])); - val = mg_unhexn(&str.ptr[j], i - j + 1); - addr->ip[n] = (uint8_t) ((val >> 8) & 255); - addr->ip[n + 1] = (uint8_t) (val & 255); - } else if (str.ptr[i] == ':') { - j = i + 1; - if (i > 0 && str.ptr[i - 1] == ':') { - dc = n; // Double colon - if (i > 1 && str.ptr[i - 2] == ':') return false; - } else if (i > 0) { - n += 2; - } - if (n > 14) return false; - addr->ip[n] = addr->ip[n + 1] = 0; // For trailing :: - } else if (str.ptr[i] == '%') { // Scope ID - for (i = i + 1; i < str.len; i++) { - if (str.ptr[i] < '0' || str.ptr[i] > '9') return false; - addr->scope_id = (uint8_t) (addr->scope_id * 10); - addr->scope_id = (uint8_t) (addr->scope_id + (str.ptr[i] - '0')); - } - } else { - return false; - } - } - if (n < 14 && dc == 42) return false; - if (n < 14) { - memmove(&addr->ip[dc + (14 - n)], &addr->ip[dc], n - dc + 2); - memset(&addr->ip[dc], 0, 14 - n); - } - - addr->is_ip6 = true; - return true; -} - -bool mg_aton(struct mg_str str, struct mg_addr *addr) { - // MG_INFO(("[%.*s]", (int) str.len, str.ptr)); - return mg_atone(str, addr) || mg_atonl(str, addr) || mg_aton4(str, addr) || - mg_aton6(str, addr); -} - -struct mg_connection *mg_alloc_conn(struct mg_mgr *mgr) { - struct mg_connection *c = - (struct mg_connection *) calloc(1, sizeof(*c) + mgr->extraconnsize); - if (c != NULL) { - c->mgr = mgr; - c->send.align = c->recv.align = c->rtls.align = MG_IO_SIZE; - c->id = ++mgr->nextid; - MG_PROF_INIT(c); - } - return c; -} - -void mg_close_conn(struct mg_connection *c) { - mg_resolve_cancel(c); // Close any pending DNS query - LIST_DELETE(struct mg_connection, &c->mgr->conns, c); - if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL; - if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL; - // Order of operations is important. `MG_EV_CLOSE` event must be fired - // before we deallocate received data, see #1331 - mg_call(c, MG_EV_CLOSE, NULL); - MG_DEBUG(("%lu %ld closed", c->id, c->fd)); - MG_PROF_DUMP(c); - MG_PROF_FREE(c); - - mg_tls_free(c); - mg_iobuf_free(&c->recv); - mg_iobuf_free(&c->send); - mg_iobuf_free(&c->rtls); - mg_bzero((unsigned char *) c, sizeof(*c)); - free(c); -} - -struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url, - mg_event_handler_t fn, void *fn_data) { - struct mg_connection *c = NULL; - if (url == NULL || url[0] == '\0') { - MG_ERROR(("null url")); - } else if ((c = mg_alloc_conn(mgr)) == NULL) { - MG_ERROR(("OOM")); - } else { - LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); - c->is_udp = (strncmp(url, "udp:", 4) == 0); - c->fd = (void *) (size_t) MG_INVALID_SOCKET; - c->fn = fn; - c->is_client = true; - c->fn_data = fn_data; - MG_DEBUG(("%lu %ld %s", c->id, c->fd, url)); - mg_call(c, MG_EV_OPEN, (void *) url); - mg_resolve(c, url); - } - return c; -} - -struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url, - mg_event_handler_t fn, void *fn_data) { - struct mg_connection *c = NULL; - if ((c = mg_alloc_conn(mgr)) == NULL) { - MG_ERROR(("OOM %s", url)); - } else if (!mg_open_listener(c, url)) { - MG_ERROR(("Failed: %s, errno %d", url, errno)); - MG_PROF_FREE(c); - free(c); - c = NULL; - } else { - c->is_listening = 1; - c->is_udp = strncmp(url, "udp:", 4) == 0; - LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); - c->fn = fn; - c->fn_data = fn_data; - mg_call(c, MG_EV_OPEN, NULL); - if (mg_url_is_ssl(url)) c->is_tls = 1; // Accepted connection must - MG_DEBUG(("%lu %ld %s", c->id, c->fd, url)); - } - return c; -} - -struct mg_connection *mg_wrapfd(struct mg_mgr *mgr, int fd, - mg_event_handler_t fn, void *fn_data) { - struct mg_connection *c = mg_alloc_conn(mgr); - if (c != NULL) { - c->fd = (void *) (size_t) fd; - c->fn = fn; - c->fn_data = fn_data; - MG_EPOLL_ADD(c); - mg_call(c, MG_EV_OPEN, NULL); - LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); - } - return c; -} - -struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds, - unsigned flags, void (*fn)(void *), void *arg) { - struct mg_timer *t = (struct mg_timer *) calloc(1, sizeof(*t)); - if (t != NULL) { - mg_timer_init(&mgr->timers, t, milliseconds, flags, fn, arg); - t->id = mgr->timerid++; - } - return t; -} - -long mg_io_recv(struct mg_connection *c, void *buf, size_t len) { - if (c->rtls.len == 0) return MG_IO_WAIT; - if (len > c->rtls.len) len = c->rtls.len; - memcpy(buf, c->rtls.buf, len); - mg_iobuf_del(&c->rtls, 0, len); - return (long) len; -} - -void mg_mgr_free(struct mg_mgr *mgr) { - struct mg_connection *c; - struct mg_timer *tmp, *t = mgr->timers; - while (t != NULL) tmp = t->next, free(t), t = tmp; - mgr->timers = NULL; // Important. Next call to poll won't touch timers - for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1; - mg_mgr_poll(mgr, 0); -#if MG_ENABLE_FREERTOS_TCP - FreeRTOS_DeleteSocketSet(mgr->ss); -#endif - MG_DEBUG(("All connections closed")); -#if MG_ENABLE_EPOLL - if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1; -#endif - mg_tls_ctx_free(mgr); -} - -void mg_mgr_init(struct mg_mgr *mgr) { - memset(mgr, 0, sizeof(*mgr)); -#if MG_ENABLE_EPOLL - if ((mgr->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0) - MG_ERROR(("epoll_create1 errno %d", errno)); -#else - mgr->epoll_fd = -1; -#endif -#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK - // clang-format off - { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); } - // clang-format on -#elif MG_ENABLE_FREERTOS_TCP - mgr->ss = FreeRTOS_CreateSocketSet(); -#elif defined(__unix) || defined(__unix__) || defined(__APPLE__) - // Ignore SIGPIPE signal, so if client cancels the request, it - // won't kill the whole process. - signal(SIGPIPE, SIG_IGN); -#endif - mgr->pipe = MG_INVALID_SOCKET; - mgr->dnstimeout = 3000; - mgr->dns4.url = "udp://8.8.8.8:53"; - mgr->dns6.url = "udp://[2001:4860:4860::8888]:53"; - mg_tls_ctx_init(mgr); -} - #ifdef MG_ENABLE_LINES #line 1 "src/net_builtin.c" #endif @@ -5583,6 +5296,289 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) { } #endif // MG_ENABLE_TCPIP +#ifdef MG_ENABLE_LINES +#line 1 "src/net.c" +#endif + + + + + + + + + +size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) { + size_t old = c->send.len; + mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap); + return c->send.len - old; +} + +size_t mg_printf(struct mg_connection *c, const char *fmt, ...) { + size_t len = 0; + va_list ap; + va_start(ap, fmt); + len = mg_vprintf(c, fmt, &ap); + va_end(ap); + return len; +} + +static bool mg_atonl(struct mg_str str, struct mg_addr *addr) { + uint32_t localhost = mg_htonl(0x7f000001); + if (mg_vcasecmp(&str, "localhost") != 0) return false; + memcpy(addr->ip, &localhost, sizeof(uint32_t)); + addr->is_ip6 = false; + return true; +} + +static bool mg_atone(struct mg_str str, struct mg_addr *addr) { + if (str.len > 0) return false; + memset(addr->ip, 0, sizeof(addr->ip)); + addr->is_ip6 = false; + return true; +} + +static bool mg_aton4(struct mg_str str, struct mg_addr *addr) { + uint8_t data[4] = {0, 0, 0, 0}; + size_t i, num_dots = 0; + for (i = 0; i < str.len; i++) { + if (str.ptr[i] >= '0' && str.ptr[i] <= '9') { + int octet = data[num_dots] * 10 + (str.ptr[i] - '0'); + if (octet > 255) return false; + data[num_dots] = (uint8_t) octet; + } else if (str.ptr[i] == '.') { + if (num_dots >= 3 || i == 0 || str.ptr[i - 1] == '.') return false; + num_dots++; + } else { + return false; + } + } + if (num_dots != 3 || str.ptr[i - 1] == '.') return false; + memcpy(&addr->ip, data, sizeof(data)); + addr->is_ip6 = false; + return true; +} + +static bool mg_v4mapped(struct mg_str str, struct mg_addr *addr) { + int i; + uint32_t ipv4; + if (str.len < 14) return false; + if (str.ptr[0] != ':' || str.ptr[1] != ':' || str.ptr[6] != ':') return false; + for (i = 2; i < 6; i++) { + if (str.ptr[i] != 'f' && str.ptr[i] != 'F') return false; + } + // struct mg_str s = mg_str_n(&str.ptr[7], str.len - 7); + if (!mg_aton4(mg_str_n(&str.ptr[7], str.len - 7), addr)) return false; + memcpy(&ipv4, addr->ip, sizeof(ipv4)); + memset(addr->ip, 0, sizeof(addr->ip)); + addr->ip[10] = addr->ip[11] = 255; + memcpy(&addr->ip[12], &ipv4, 4); + addr->is_ip6 = true; + return true; +} + +static bool mg_aton6(struct mg_str str, struct mg_addr *addr) { + size_t i, j = 0, n = 0, dc = 42; + addr->scope_id = 0; + if (str.len > 2 && str.ptr[0] == '[') str.ptr++, str.len -= 2; + if (mg_v4mapped(str, addr)) return true; + for (i = 0; i < str.len; i++) { + if ((str.ptr[i] >= '0' && str.ptr[i] <= '9') || + (str.ptr[i] >= 'a' && str.ptr[i] <= 'f') || + (str.ptr[i] >= 'A' && str.ptr[i] <= 'F')) { + unsigned long val; + if (i > j + 3) return false; + // MG_DEBUG(("%lu %lu [%.*s]", i, j, (int) (i - j + 1), &str.ptr[j])); + val = mg_unhexn(&str.ptr[j], i - j + 1); + addr->ip[n] = (uint8_t) ((val >> 8) & 255); + addr->ip[n + 1] = (uint8_t) (val & 255); + } else if (str.ptr[i] == ':') { + j = i + 1; + if (i > 0 && str.ptr[i - 1] == ':') { + dc = n; // Double colon + if (i > 1 && str.ptr[i - 2] == ':') return false; + } else if (i > 0) { + n += 2; + } + if (n > 14) return false; + addr->ip[n] = addr->ip[n + 1] = 0; // For trailing :: + } else if (str.ptr[i] == '%') { // Scope ID + for (i = i + 1; i < str.len; i++) { + if (str.ptr[i] < '0' || str.ptr[i] > '9') return false; + addr->scope_id = (uint8_t) (addr->scope_id * 10); + addr->scope_id = (uint8_t) (addr->scope_id + (str.ptr[i] - '0')); + } + } else { + return false; + } + } + if (n < 14 && dc == 42) return false; + if (n < 14) { + memmove(&addr->ip[dc + (14 - n)], &addr->ip[dc], n - dc + 2); + memset(&addr->ip[dc], 0, 14 - n); + } + + addr->is_ip6 = true; + return true; +} + +bool mg_aton(struct mg_str str, struct mg_addr *addr) { + // MG_INFO(("[%.*s]", (int) str.len, str.ptr)); + return mg_atone(str, addr) || mg_atonl(str, addr) || mg_aton4(str, addr) || + mg_aton6(str, addr); +} + +struct mg_connection *mg_alloc_conn(struct mg_mgr *mgr) { + struct mg_connection *c = + (struct mg_connection *) calloc(1, sizeof(*c) + mgr->extraconnsize); + if (c != NULL) { + c->mgr = mgr; + c->send.align = c->recv.align = c->rtls.align = MG_IO_SIZE; + c->id = ++mgr->nextid; + MG_PROF_INIT(c); + } + return c; +} + +void mg_close_conn(struct mg_connection *c) { + mg_resolve_cancel(c); // Close any pending DNS query + LIST_DELETE(struct mg_connection, &c->mgr->conns, c); + if (c == c->mgr->dns4.c) c->mgr->dns4.c = NULL; + if (c == c->mgr->dns6.c) c->mgr->dns6.c = NULL; + // Order of operations is important. `MG_EV_CLOSE` event must be fired + // before we deallocate received data, see #1331 + mg_call(c, MG_EV_CLOSE, NULL); + MG_DEBUG(("%lu %ld closed", c->id, c->fd)); + MG_PROF_DUMP(c); + MG_PROF_FREE(c); + + mg_tls_free(c); + mg_iobuf_free(&c->recv); + mg_iobuf_free(&c->send); + mg_iobuf_free(&c->rtls); + mg_bzero((unsigned char *) c, sizeof(*c)); + free(c); +} + +struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url, + mg_event_handler_t fn, void *fn_data) { + struct mg_connection *c = NULL; + if (url == NULL || url[0] == '\0') { + MG_ERROR(("null url")); + } else if ((c = mg_alloc_conn(mgr)) == NULL) { + MG_ERROR(("OOM")); + } else { + LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); + c->is_udp = (strncmp(url, "udp:", 4) == 0); + c->fd = (void *) (size_t) MG_INVALID_SOCKET; + c->fn = fn; + c->is_client = true; + c->fn_data = fn_data; + MG_DEBUG(("%lu %ld %s", c->id, c->fd, url)); + mg_call(c, MG_EV_OPEN, (void *) url); + mg_resolve(c, url); + } + return c; +} + +struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url, + mg_event_handler_t fn, void *fn_data) { + struct mg_connection *c = NULL; + if ((c = mg_alloc_conn(mgr)) == NULL) { + MG_ERROR(("OOM %s", url)); + } else if (!mg_open_listener(c, url)) { + MG_ERROR(("Failed: %s, errno %d", url, errno)); + MG_PROF_FREE(c); + free(c); + c = NULL; + } else { + c->is_listening = 1; + c->is_udp = strncmp(url, "udp:", 4) == 0; + LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); + c->fn = fn; + c->fn_data = fn_data; + mg_call(c, MG_EV_OPEN, NULL); + if (mg_url_is_ssl(url)) c->is_tls = 1; // Accepted connection must + MG_DEBUG(("%lu %ld %s", c->id, c->fd, url)); + } + return c; +} + +struct mg_connection *mg_wrapfd(struct mg_mgr *mgr, int fd, + mg_event_handler_t fn, void *fn_data) { + struct mg_connection *c = mg_alloc_conn(mgr); + if (c != NULL) { + c->fd = (void *) (size_t) fd; + c->fn = fn; + c->fn_data = fn_data; + MG_EPOLL_ADD(c); + mg_call(c, MG_EV_OPEN, NULL); + LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c); + } + return c; +} + +struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds, + unsigned flags, void (*fn)(void *), void *arg) { + struct mg_timer *t = (struct mg_timer *) calloc(1, sizeof(*t)); + if (t != NULL) { + mg_timer_init(&mgr->timers, t, milliseconds, flags, fn, arg); + t->id = mgr->timerid++; + } + return t; +} + +long mg_io_recv(struct mg_connection *c, void *buf, size_t len) { + if (c->rtls.len == 0) return MG_IO_WAIT; + if (len > c->rtls.len) len = c->rtls.len; + memcpy(buf, c->rtls.buf, len); + mg_iobuf_del(&c->rtls, 0, len); + return (long) len; +} + +void mg_mgr_free(struct mg_mgr *mgr) { + struct mg_connection *c; + struct mg_timer *tmp, *t = mgr->timers; + while (t != NULL) tmp = t->next, free(t), t = tmp; + mgr->timers = NULL; // Important. Next call to poll won't touch timers + for (c = mgr->conns; c != NULL; c = c->next) c->is_closing = 1; + mg_mgr_poll(mgr, 0); +#if MG_ENABLE_FREERTOS_TCP + FreeRTOS_DeleteSocketSet(mgr->ss); +#endif + MG_DEBUG(("All connections closed")); +#if MG_ENABLE_EPOLL + if (mgr->epoll_fd >= 0) close(mgr->epoll_fd), mgr->epoll_fd = -1; +#endif + mg_tls_ctx_free(mgr); +} + +void mg_mgr_init(struct mg_mgr *mgr) { + memset(mgr, 0, sizeof(*mgr)); +#if MG_ENABLE_EPOLL + if ((mgr->epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0) + MG_ERROR(("epoll_create1 errno %d", errno)); +#else + mgr->epoll_fd = -1; +#endif +#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK + // clang-format off + { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); } + // clang-format on +#elif MG_ENABLE_FREERTOS_TCP + mgr->ss = FreeRTOS_CreateSocketSet(); +#elif defined(__unix) || defined(__unix__) || defined(__APPLE__) + // Ignore SIGPIPE signal, so if client cancels the request, it + // won't kill the whole process. + signal(SIGPIPE, SIG_IGN); +#endif + mgr->pipe = MG_INVALID_SOCKET; + mgr->dnstimeout = 3000; + mgr->dns4.url = "udp://8.8.8.8:53"; + mgr->dns6.url = "udp://[2001:4860:4860::8888]:53"; + mg_tls_ctx_init(mgr); +} + #ifdef MG_ENABLE_LINES #line 1 "src/ota_dummy.c" #endif @@ -6630,7 +6626,7 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) { return res; } -static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void sntp_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { int64_t milliseconds = mg_sntp_parse(c->recv.buf, c->recv.len); if (milliseconds > 0) { @@ -6644,8 +6640,7 @@ static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { mg_sntp_request(c); } else if (ev == MG_EV_CLOSE) { } - (void) fnd; - (void) evd; + (void) ev_data; } void mg_sntp_request(struct mg_connection *c) { @@ -7296,7 +7291,7 @@ static bool mg_socketpair(MG_SOCKET_TYPE sp[2], union usa usa[2]) { } // mg_wakeup() event handler -static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void wufn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { unsigned long *id = (unsigned long *) c->recv.buf; // MG_INFO(("Got data")); @@ -7316,7 +7311,7 @@ static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) { closesocket(c->mgr->pipe); // When we're closing, close the other c->mgr->pipe = MG_INVALID_SOCKET; // side of the socketpair, too } - (void) evd, (void) fnd; + (void) ev_data; } bool mg_wakeup_init(struct mg_mgr *mgr) { @@ -13736,8 +13731,7 @@ static bool mg_ws_client_handshake(struct mg_connection *c) { return false; // Continue event handler } -static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) { struct ws_msg msg; size_t ofs = (size_t) c->pfn_data; @@ -13803,7 +13797,6 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, } } } - (void) fn_data; (void) ev_data; } diff --git a/mongoose.h b/mongoose.h index ca54a243..aa4b815d 100644 --- a/mongoose.h +++ b/mongoose.h @@ -2096,7 +2096,7 @@ typedef uint64_t uECC_word_t; struct mg_connection; typedef void (*mg_event_handler_t)(struct mg_connection *, int ev, - void *ev_data, void *fn_data); + void *ev_data); void mg_call(struct mg_connection *c, int ev, void *ev_data); void mg_error(struct mg_connection *c, const char *fmt, ...); diff --git a/src/dns.c b/src/dns.c index 675f20de..0df92881 100644 --- a/src/dns.c +++ b/src/dns.c @@ -134,8 +134,7 @@ bool mg_dns_parse(const uint8_t *buf, size_t len, struct mg_dns_message *dm) { return true; } -static void dns_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void dns_cb(struct mg_connection *c, int ev, void *ev_data) { struct dns_data *d, *tmp; struct dns_data **head = (struct dns_data **) &c->mgr->active_dns_requests; if (ev == MG_EV_POLL) { @@ -189,7 +188,6 @@ static void dns_cb(struct mg_connection *c, int ev, void *ev_data, mg_dns_free(head, d); } } - (void) fn_data; } static bool mg_dns_send(struct mg_connection *c, const struct mg_str *name, diff --git a/src/event.c b/src/event.c index b50d246a..e6217f40 100644 --- a/src/event.c +++ b/src/event.c @@ -19,8 +19,8 @@ void mg_call(struct mg_connection *c, int ev, void *ev_data) { // Run user-defined handler first, in order to give it an ability // to intercept processing (e.g. clean input buffer) before the // protocol handler kicks in - if (c->fn != NULL) c->fn(c, ev, ev_data, c->fn_data); - if (c->pfn != NULL) c->pfn(c, ev, ev_data, c->pfn_data); + if (c->fn != NULL) c->fn(c, ev, ev_data); + if (c->pfn != NULL) c->pfn(c, ev, ev_data); } void mg_error(struct mg_connection *c, const char *fmt, ...) { @@ -31,5 +31,5 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) { va_end(ap); MG_ERROR(("%lu %ld %s", c->id, c->fd, buf)); c->is_closing = 1; // Set is_closing before sending MG_EV_CALL - mg_call(c, MG_EV_ERROR, buf); // Let user handler to override it + mg_call(c, MG_EV_ERROR, buf); // Let user handler override it } diff --git a/src/event.h b/src/event.h index 8fb521d5..12414379 100644 --- a/src/event.h +++ b/src/event.h @@ -2,7 +2,7 @@ struct mg_connection; typedef void (*mg_event_handler_t)(struct mg_connection *, int ev, - void *ev_data, void *fn_data); + void *ev_data); void mg_call(struct mg_connection *c, int ev, void *ev_data); void mg_error(struct mg_connection *c, const char *fmt, ...); diff --git a/src/http.c b/src/http.c index c9488683..16608089 100644 --- a/src/http.c +++ b/src/http.c @@ -1,7 +1,7 @@ +#include "http.h" #include "arch.h" #include "base64.h" #include "fmt.h" -#include "http.h" #include "json.h" #include "log.h" #include "net.h" @@ -431,7 +431,7 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers, c->is_resp = 0; } -static void http_cb(struct mg_connection *, int, void *, void *); +static void http_cb(struct mg_connection *, int, void *); static void restore_http_cb(struct mg_connection *c) { mg_fs_close((struct mg_fd *) c->pfn_data); c->pfn_data = NULL; @@ -445,10 +445,9 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) { return buf; } -static void static_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void static_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_WRITE || ev == MG_EV_POLL) { - struct mg_fd *fd = (struct mg_fd *) fn_data; + struct mg_fd *fd = (struct mg_fd *) c->pfn_data; // Read to send IO buffer directly, avoid extra on-stack buffer size_t n, max = MG_IO_SIZE, space; size_t *cl = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) / @@ -973,7 +972,7 @@ static int skip_chunk(const char *buf, int len, int *pl, int *dl) { return i + 2 + n + 2; } -static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void http_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ || ev == MG_EV_CLOSE) { struct mg_http_message hm; size_t ofs = 0; // Parsing offset @@ -1035,10 +1034,10 @@ static void http_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { } if (ofs > 0) mg_iobuf_del(&c->recv, 0, ofs); // Delete processed data } - (void) evd, (void) fnd; + (void) ev_data; } -static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { +static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (mg_http_match_uri(hm, "/quit")) { @@ -1053,7 +1052,7 @@ static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) { mg_http_reply(c, 200, "", "hi\n"); } } else if (ev == MG_EV_CLOSE) { - if (c->data[0] == 'X') *(bool *) fnd = true; + if (c->data[0] == 'X') *(bool *) c->fn_data = true; } } diff --git a/src/mqtt.c b/src/mqtt.c index 5301f586..8531424b 100644 --- a/src/mqtt.c +++ b/src/mqtt.c @@ -410,7 +410,8 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version, } if (p > end) return MQTT_MALFORMED; if (version == 5 && p + 2 < end) { - len_len = (uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size); + len_len = + (uint32_t) decode_varint(p, (size_t) (end - p), &m->props_size); if (!len_len) return MQTT_MALFORMED; m->props_start = (size_t) (p + len_len - buf); p += len_len + m->props_size; @@ -426,8 +427,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version, return MQTT_OK; } -static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { for (;;) { uint8_t version = c->is_mqtt5 ? 5 : 4; @@ -495,7 +495,6 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data, } } (void) ev_data; - (void) fn_data; } void mg_mqtt_ping(struct mg_connection *nc) { diff --git a/src/sntp.c b/src/sntp.c index 046ac6b5..b3f2962c 100644 --- a/src/sntp.c +++ b/src/sntp.c @@ -38,7 +38,7 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) { return res; } -static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void sntp_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { int64_t milliseconds = mg_sntp_parse(c->recv.buf, c->recv.len); if (milliseconds > 0) { @@ -52,8 +52,7 @@ static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { mg_sntp_request(c); } else if (ev == MG_EV_CLOSE) { } - (void) fnd; - (void) evd; + (void) ev_data; } void mg_sntp_request(struct mg_connection *c) { diff --git a/src/sock.c b/src/sock.c index 4823caec..6d98dd2a 100644 --- a/src/sock.c +++ b/src/sock.c @@ -620,7 +620,7 @@ static bool mg_socketpair(MG_SOCKET_TYPE sp[2], union usa usa[2]) { } // mg_wakeup() event handler -static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void wufn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_READ) { unsigned long *id = (unsigned long *) c->recv.buf; // MG_INFO(("Got data")); @@ -640,7 +640,7 @@ static void wufn(struct mg_connection *c, int ev, void *evd, void *fnd) { closesocket(c->mgr->pipe); // When we're closing, close the other c->mgr->pipe = MG_INVALID_SOCKET; // side of the socketpair, too } - (void) evd, (void) fnd; + (void) ev_data; } bool mg_wakeup_init(struct mg_mgr *mgr) { diff --git a/src/ws.c b/src/ws.c index 38f904db..7fc8b116 100644 --- a/src/ws.c +++ b/src/ws.c @@ -163,8 +163,7 @@ static bool mg_ws_client_handshake(struct mg_connection *c) { return false; // Continue event handler } -static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data) { struct ws_msg msg; size_t ofs = (size_t) c->pfn_data; @@ -230,7 +229,6 @@ static void mg_ws_cb(struct mg_connection *c, int ev, void *ev_data, } } } - (void) fn_data; (void) ev_data; } diff --git a/test/fuzz.c b/test/fuzz.c index a0eb8d5a..5301c147 100644 --- a/test/fuzz.c +++ b/test/fuzz.c @@ -14,12 +14,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *, size_t); int LLVMFuzzerTestOneInput(const uint8_t *, size_t); #endif -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn(struct mg_connection *c, int ev, void *ev_data) { struct mg_http_serve_opts opts = {.root_dir = "."}; if (ev == MG_EV_HTTP_MSG) { mg_http_serve_dir(c, (struct mg_http_message *) ev_data, &opts); } - (void) fn_data; } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -110,7 +109,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { const char *url = "http://localhost:12345"; struct mg_connection *c = mg_http_connect(&mgr, url, fn, NULL); mg_iobuf_add(&c->recv, 0, data, size); - c->pfn(c, MG_EV_READ, NULL, NULL); + c->pfn(c, MG_EV_READ, NULL); // manually invoke protocol event handler mg_mgr_free(&mgr); free(pkt); diff --git a/test/mip_tap_test.c b/test/mip_tap_test.c index dcb8a93a..4fd1e3ef 100644 --- a/test/mip_tap_test.c +++ b/test/mip_tap_test.c @@ -59,18 +59,16 @@ struct Post_reply { }; char *fetch(struct mg_mgr *mgr, const char *url, const char *post_data); -static void f_http_fetch_query(struct mg_connection *c, int ev, void *ev_data, - void *fn_data); +static void f_http_fetch_query(struct mg_connection *c, int ev, void *ev_data); int get_response_code(char *); // Returns HTTP status code from full char* msg -static void f_http_fetch_query(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void f_http_fetch_query(struct mg_connection *c, int ev, void *ev_data) { static char *http_response = 0; static bool http_response_allocated = 0; // So that we will update out parameter unsigned int http_responses_received = 0; struct Post_reply *post_reply_l; - post_reply_l = (struct Post_reply *) fn_data; + post_reply_l = (struct Post_reply *) c->fn_data; if (ev == MG_EV_CONNECT) { mg_printf(c, post_reply_l->post); @@ -159,8 +157,7 @@ static void test_http_fetch(struct mg_mgr *mgr) { static struct mg_connection *s_conn; static char s_topic[16]; -static void mqtt_fn(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void mqtt_fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_MQTT_OPEN) { // MQTT connect is successful struct mg_mqtt_opts sub_opts; @@ -180,7 +177,7 @@ static void mqtt_fn(struct mg_connection *c, int ev, void *ev_data, ASSERT(0); if (mm->data.len != 2 || strcmp(mm->data.ptr, "hi")) ASSERT(0); mg_mqtt_disconnect(c, NULL); - *(bool *) fn_data = true; + *(bool *) c->fn_data = true; } else if (ev == MG_EV_CLOSE) { s_conn = NULL; } diff --git a/test/mip_test.c b/test/mip_test.c index 5e2dcdd9..a143b999 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -30,25 +30,25 @@ static void test_statechange(void) { onstatechange(&iface); } -static void ph(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - if (ev == MG_EV_POLL) ++(*(int *) fn_data); +static void ph(struct mg_connection *c, int ev, void *ev_data) { + if (ev == MG_EV_POLL) ++(*(int *) c->fn_data); (void) c, (void) ev_data; } -static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - (void) c, (void) ev, (void) ev_data, (void) fn_data; +static void fn(struct mg_connection *c, int ev, void *ev_data) { + (void) c, (void) ev, (void) ev_data; } -static void frag_recv_fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void frag_recv_fn(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ERROR) { if (s_sent_fragment) { ASSERT(strcmp((char*) ev_data, "Received fragmented packet") == 0); } } - (void) c, (void) ev_data, (void) fn_data; + (void) c, (void) ev_data; } -static void frag_send_fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void frag_send_fn(struct mg_connection *c, int ev, void *ev_data) { static bool s_sent; static int s_seg_sizes[] = {416, 416, 368}; if (ev == MG_EV_POLL) { @@ -60,7 +60,7 @@ static void frag_send_fn(struct mg_connection *c, int ev, void *ev_data, void *f // Checking TCP segment sizes (ev_data points to the TCP payload length) ASSERT(*(int *) ev_data == s_seg_sizes[s_seg_sent++]); } - (void) c, (void) ev_data, (void) fn_data; + (void) c, (void) ev_data; } static void test_poll(void) { diff --git a/test/unit_test.c b/test/unit_test.c index 79d1315a..a219b2a3 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -344,10 +344,10 @@ static void test_iobuf(void) { mg_iobuf_free(&io); } -static void sntp_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { +static void sntp_cb(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_SNTP_TIME) { - int64_t received = *(int64_t *) evd; - *(int64_t *) fnd = received; + int64_t received = *(int64_t *) ev_data; + *(int64_t *) c->fn_data = received; MG_DEBUG(("got time: %lld", received)); #if MG_ARCH == MG_ARCH_UNIX struct timeval tv = {0, 0}; @@ -409,16 +409,16 @@ struct mqtt_data { #define flags_released (1 << 3) #define flags_completed (1 << 4) -static void mqtt_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { - struct mqtt_data *test_data = (struct mqtt_data *) fnd; +static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) { + struct mqtt_data *test_data = (struct mqtt_data *) c->fn_data; char *buf = test_data->msg; if (ev == MG_EV_MQTT_OPEN) { - buf[0] = *(int *) evd == 0 ? 'X' : 'Y'; + buf[0] = *(int *) ev_data == 0 ? 'X' : 'Y'; } else if (ev == MG_EV_CLOSE) { buf[0] = 0; } else if (ev == MG_EV_MQTT_CMD) { - struct mg_mqtt_message *mm = (struct mg_mqtt_message *) evd; + struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; if (mm->cmd == MQTT_CMD_SUBACK) { test_data->flags = flags_subscribed; } else if (mm->cmd == MQTT_CMD_PUBACK) { // here we assume the broker @@ -431,7 +431,7 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *evd, void *fnd) { test_data->flags |= flags_completed; } } else if (ev == MG_EV_MQTT_MSG) { - struct mg_mqtt_message *mm = (struct mg_mqtt_message *) evd; + struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data; snprintf(test_data->topic, test_data->topicsize, "%.*s", (int) mm->topic.len, mm->topic.ptr); snprintf(buf + 1, test_data->msgsize - 2, "%.*s", (int) mm->data.len, @@ -686,8 +686,8 @@ static void test_mqtt(void) { test_mqtt_ver(5); } -static void eh1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct mg_tls_opts *topts = (struct mg_tls_opts *) fn_data; +static void eh1(struct mg_connection *c, int ev, void *ev_data) { + struct mg_tls_opts *topts = (struct mg_tls_opts *) c->fn_data; if (ev == MG_EV_ACCEPT && topts != NULL) mg_tls_init(c, topts); if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; @@ -751,7 +751,6 @@ static void eh1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; mg_ws_send(c, wm->data.ptr, wm->data.len, WEBSOCKET_OP_BINARY); } - (void) fn_data; } struct fetch_data { @@ -759,8 +758,8 @@ struct fetch_data { int code, closed; }; -static void fcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct fetch_data *fd = (struct fetch_data *) fn_data; +static void fcb(struct mg_connection *c, int ev, void *ev_data) { + struct fetch_data *fd = (struct fetch_data *) c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; snprintf(fd->buf, FETCH_BUF_SIZE, "%.*s", (int) hm->message.len, @@ -827,8 +826,8 @@ static bool cmpheader(const char *buf, const char *name, const char *value) { return h != NULL && mg_strcmp(*h, mg_str(value)) == 0; } -static void wcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - int *p = (int *) fn_data; +static void wcb(struct mg_connection *c, int ev, void *ev_data) { + int *p = (int *) c->fn_data; if (ev == MG_EV_WS_OPEN) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_str *wsproto = mg_http_get_header(hm, "Sec-WebSocket-Protocol"); @@ -848,7 +847,7 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } } -static void ew2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void ew2(struct mg_connection *c, int ev, void *ev_data) { size_t size = 65 * 1024 + 737; if (ev == MG_EV_WS_OPEN) { char *msg = (char *) calloc(1, size + 1); @@ -866,7 +865,7 @@ static void ew2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (wm->data.ptr[i] != 'A') ok = 0; } ASSERT(ok == 1); - *(int *) fn_data = 1; + *(int *) c->fn_data = 1; } } } @@ -897,10 +896,10 @@ static void test_ws(void) { ASSERT(mgr.conns == NULL); } -static void eh9(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void eh9(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ERROR) { ASSERT(!strcmp((char *) ev_data, "socket error")); - *(int *) fn_data = 7; + *(int *) c->fn_data = 7; } (void) c; } @@ -1166,7 +1165,7 @@ static void test_http_server(void) { ASSERT(mgr.conns == NULL); } -static void h4(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void h4(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; MG_INFO(("[%.*s %.*s] message len %d", (int) hm->method.len, hm->method.ptr, @@ -1190,7 +1189,6 @@ static void h4(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { mg_http_serve_dir(c, hm, &opts); } } - (void) fn_data; } static void test_http_404(void) { @@ -1242,8 +1240,8 @@ static void test_tls(void) { #endif } -static void f3(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - int *ok = (int *) fn_data; +static void f3(struct mg_connection *c, int ev, void *ev_data) { + int *ok = (int *) c->fn_data; // MG_INFO(("%d", ev)); if (ev == MG_EV_CONNECT) { // c->is_hexdumping = 1; @@ -1358,27 +1356,27 @@ static void test_host_validation(void) { #endif } -static void f4(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void f4(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; mg_printf(c, "HTTP/1.0 200 OK\n\n%.*s/%s", (int) hm->uri.len, hm->uri.ptr, "abcdef"); - strcat((char *) fn_data, "m"); + strcat((char *) c->fn_data, "m"); c->is_draining = 1; } else if (ev == MG_EV_CLOSE) { - strcat((char *) fn_data, "c"); + strcat((char *) c->fn_data, "c"); } } -static void f4c(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void f4c(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_CONNECT) { mg_printf(c, "GET /foo/bar HTTP/1.0\n\n"); } else if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; ASSERT(mg_strcmp(hm->body, mg_str("/foo/bar/abcdef")) == 0); - strcat((char *) fn_data, "m"); + strcat((char *) c->fn_data, "m"); } else if (ev == MG_EV_CLOSE) { - strcat((char *) fn_data, "c"); + strcat((char *) c->fn_data, "c"); } } @@ -1398,11 +1396,11 @@ static void test_http_no_content_length(void) { ASSERT(mgr.conns == NULL); } -static void f5(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void f5(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; mg_http_reply(c, 200, "", "%.*s", (int) hm->uri.len, hm->uri.ptr); - (*(int *) fn_data)++; + (*(int *) c->fn_data)++; } } @@ -1616,7 +1614,7 @@ static void test_http_parse(void) { } } -static void ehr(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void ehr(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_serve_opts opts; @@ -1624,7 +1622,6 @@ static void ehr(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { opts.root_dir = "./test/data"; mg_http_serve_dir(c, hm, &opts); } - (void) fn_data; } static void test_http_range(void) { @@ -2109,10 +2106,10 @@ static void test_str(void) { } } -static void fn1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void fn1(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_ERROR) { - free(*(char **) fn_data); // See #2263 - *(char **) fn_data = mg_mprintf("%s", (char *) ev_data); + free(*(char **) c->fn_data); // See #2263 + *(char **) c->fn_data = mg_mprintf("%s", (char *) ev_data); } (void) c; } @@ -2329,7 +2326,7 @@ static void test_crc32(void) { ASSERT(mg_crc32(mg_crc32(0, "ab", 2), "c", 1) == 891568578); } -static void us(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void us(struct mg_connection *c, int ev, void *ev_data) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; if (ev == MG_EV_HTTP_MSG && mg_http_match_uri(hm, "/upload")) { MG_DEBUG(("Got all %lu bytes!", (unsigned long) hm->body.len)); @@ -2340,11 +2337,10 @@ static void us(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_HTTP_MSG) { mg_http_reply(c, 200, "", "ok\n"); } - (void) fn_data; } -static void uc(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - const char **s = (const char **) fn_data; +static void uc(struct mg_connection *c, int ev, void *ev_data) { + const char **s = (const char **) c->fn_data; if (ev == MG_EV_OPEN) { // c->is_hexdumping = 1; } else if (ev == MG_EV_CONNECT) { @@ -2360,7 +2356,6 @@ static void uc(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { ASSERT(mg_strcmp(hm->body, mg_str(*s)) == 0); *s = NULL; } - (void) fn_data; } static void test_http_upload(void) { @@ -2380,7 +2375,7 @@ static void test_http_upload(void) { #define LONG_CHUNK "chunk with length taking up more than two hex digits" -static void eX(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void eX(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); c->data[0] = 1; @@ -2398,10 +2393,10 @@ static void eX(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { c->data[0] = 0; } } - (void) ev_data, (void) fn_data; + (void) ev_data; } -static void eY(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void eY(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { mg_printf(c, "HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\n"); c->data[0] = 1; @@ -2411,19 +2406,19 @@ static void eY(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (c->data[0] == 12) mg_send(c, "bc", 2); if (c->data[0] == 30) mg_send(c, "d", 1), c->is_resp = 0, c->data[0] = 0; } - (void) ev_data, (void) fn_data; + (void) ev_data; } -static void eZ(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void eZ(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { mg_http_reply(c, 200, "", "abcd"); } - (void) ev_data, (void) fn_data; + (void) ev_data; } // Do not delete chunks as they arrive -static void eh4(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - uint32_t *crc = (uint32_t *) fn_data; +static void eh4(struct mg_connection *c, int ev, void *ev_data) { + uint32_t *crc = (uint32_t *) c->fn_data; if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; *crc = mg_crc32(*crc, hm->body.ptr, hm->body.len); @@ -2486,8 +2481,8 @@ struct stream_status { }; // Consume recv buffer after letting it reach MG_MAX_RECV_SIZE -static void eh8(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - struct stream_status *status = (struct stream_status *) fn_data; +static void eh8(struct mg_connection *c, int ev, void *ev_data) { + struct stream_status *status = (struct stream_status *) c->fn_data; if (c->is_listening) return; ASSERT(c->recv.len <= MG_MAX_RECV_SIZE); @@ -2523,19 +2518,17 @@ static void eh8(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } // Toggle c->is_full to prevent max_recv_buf_size reached read errors -static void eh10(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { +static void eh10(struct mg_connection *c, int ev, void *ev_data) { if (c->recv.len >= MG_MAX_RECV_SIZE && ev == MG_EV_READ) c->is_full = true; - eh8(c, ev, ev_data, fn_data); + eh8(c, ev, ev_data); if (c->recv.len < MG_MAX_RECV_SIZE && ev == MG_EV_POLL) c->is_full = false; } // Send buffer larger than MG_MAX_RECV_SIZE to server -static void eh11(struct mg_connection *c, int ev, void *ev_data, - void *fn_data) { - struct stream_status *status = (struct stream_status *) fn_data; +static void eh11(struct mg_connection *c, int ev, void *ev_data) { + struct stream_status *status = (struct stream_status *) c->fn_data; if (ev == MG_EV_CONNECT) { size_t len = MG_MAX_RECV_SIZE * 2; struct mg_iobuf buf = {NULL, 0, 0, 0}; @@ -2548,7 +2541,6 @@ static void eh11(struct mg_connection *c, int ev, void *ev_data, mg_iobuf_free(&buf); } (void) ev_data; - (void) fn_data; } static void test_http_stream_buffer(void) { @@ -2601,7 +2593,7 @@ static void test_multipart(void) { ASSERT(mg_http_next_multipart(mg_str(s), ofs, &part) == 0); } -static void eh7(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void eh7(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_serve_opts sopts; @@ -2610,7 +2602,6 @@ static void eh7(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { sopts.fs = &mg_fs_packed; mg_http_serve_dir(c, hm, &sopts); } - (void) fn_data; } static void test_packed(void) { @@ -2655,14 +2646,14 @@ int send(int sock, const void *buf, size_t len, int flags) { } #endif -static void u1(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void u1(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_CONNECT) { - ((int *) fn_data)[0] += 1; + ((int *) c->fn_data)[0] += 1; mg_send(c, "hi", 2); } else if (ev == MG_EV_WRITE) { - ((int *) fn_data)[0] += 100; + ((int *) c->fn_data)[0] += 100; } else if (ev == MG_EV_READ) { - ((int *) fn_data)[0] += 10; + ((int *) c->fn_data)[0] += 10; mg_iobuf_free(&c->recv); } (void) ev_data; @@ -2698,7 +2689,7 @@ static void test_check_ip_acl(void) { -1); // not yet supported } -static void w3(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void w3(struct mg_connection *c, int ev, void *ev_data) { // MG_INFO(("ev %d", ev)); if (ev == MG_EV_WS_OPEN) { char buf[8192]; @@ -2711,20 +2702,20 @@ static void w3(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { } else if (ev == MG_EV_WS_MSG) { struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; ASSERT(mg_strcmp(wm->data, mg_str("lebowski")) == 0); - ((int *) fn_data)[0]++; + ((int *) c->fn_data)[0]++; } else if (ev == MG_EV_CLOSE) { - ((int *) fn_data)[0] += 10; + ((int *) c->fn_data)[0] += 10; } } -static void w2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void w2(struct mg_connection *c, int ev, void *ev_data) { struct mg_str msg = mg_str_n("lebowski", 8); if (ev == MG_EV_HTTP_MSG) { mg_ws_upgrade(c, (struct mg_http_message *) ev_data, NULL); } else if (ev == MG_EV_WS_OPEN) { mg_ws_send(c, "x", 1, WEBSOCKET_OP_PONG); } else if (ev == MG_EV_POLL && c->is_websocket) { - size_t ofs, n = (size_t) fn_data; + size_t ofs, n = (size_t) c->fn_data; if (n < msg.len) { // Send "msg" char by char using fragmented frames // mg_ws_send() sets the FIN flag in the WS header. Clean it @@ -2771,7 +2762,7 @@ static void test_ws_fragmentation(void) { ASSERT(mgr.conns == NULL); } -static void h7(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { +static void h7(struct mg_connection *c, int ev, void *ev_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_serve_opts opts; @@ -2779,7 +2770,6 @@ static void h7(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { opts.root_dir = "./test/data,/foo=./src"; mg_http_serve_dir(c, hm, &opts); } - (void) fn_data; } static void test_rewrites(void) { @@ -3111,8 +3101,8 @@ static void test_rpc(void) { ASSERT(head == NULL); } -static void ph(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { - if (ev == MG_EV_POLL) ++(*(int *) fn_data); +static void ph(struct mg_connection *c, int ev, void *ev_data) { + if (ev == MG_EV_POLL) ++(*(int *) c->fn_data); (void) c, (void) ev_data; }