C89 compatibility for http-restful-server

This commit is contained in:
Sergey Lyubka 2024-07-27 07:00:51 +01:00
parent 657717d0fb
commit 09275ae4ca

View File

@ -53,21 +53,23 @@ static const char *s_tls_key =
// fn_data is NULL for plain HTTP, and non-NULL for HTTPS
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 = {
struct mg_tls_opts opts;
memset(&opts, 0, sizeof(opts));
#ifdef TLS_TWOWAY
.ca = mg_str(s_tls_ca),
opts.ca = mg_str(s_tls_ca);
#endif
.cert = mg_str(s_tls_cert),
.key = mg_str(s_tls_key)};
opts.cert = mg_str(s_tls_cert);
opts.key = mg_str(s_tls_key);
mg_tls_init(c, &opts);
}
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_match(hm->uri, mg_str("/api/stats"), NULL)) {
struct mg_connection *t;
// Print some statistics about currently established connections
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n");
for (struct mg_connection *t = c->mgr->conns; t != NULL; t = t->next) {
for (t = c->mgr->conns; t != NULL; t = t->next) {
mg_http_printf_chunk(c, "%-3lu %4s %s %M %M\n", t->id,
t->is_udp ? "UDP" : "TCP",
t->is_listening ? "LISTENING"
@ -77,7 +79,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
}
mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk
} else if (mg_match(hm->uri, mg_str("/api/f2/*"), NULL)) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", hm->uri.len,
hm->uri.buf);
} else {
struct mg_http_serve_opts opts = {.root_dir = s_root_dir};