From 5a2e42ae25bed932c6308d77d65d1f7cab415600 Mon Sep 17 00:00:00 2001 From: cpq Date: Sun, 3 May 2026 08:40:24 +0100 Subject: [PATCH] Untie dash.c from packed fs --- mongoose.c | 2 +- src/dash.c | 2 +- tutorials/core/embedded-filesystem/packed_fs.c | 16 ++++++++-------- tutorials/device-dashboard/full/dashboard.c | 1 + tutorials/device-dashboard/minimal/dashboard.c | 1 + 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/mongoose.c b/mongoose.c index d36f3aee..77f0d227 100644 --- a/mongoose.c +++ b/mongoose.c @@ -121,6 +121,7 @@ fail: #endif + #define MG_NO_CACHE_HEADERS "Cache-Control: no-cache\r\n" #define MG_JSON_HEADERS "Content-Type: application/json\r\n" MG_NO_CACHE_HEADERS @@ -574,7 +575,6 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) { struct mg_http_serve_opts opts; memset(&opts, 0, sizeof(opts)); opts.fs = &mg_fs_packed; - mg_mem_files = mg_packed_files; mg_http_serve_file(c, hm, "/dashboard.html", &opts); } else { struct mg_dash_custom_handler *ch = dash->custom_handlers; diff --git a/src/dash.c b/src/dash.c index 62d4947e..8bcba562 100644 --- a/src/dash.c +++ b/src/dash.c @@ -1,4 +1,5 @@ #include "dash.h" +#include "util.h" #define MG_NO_CACHE_HEADERS "Cache-Control: no-cache\r\n" #define MG_JSON_HEADERS "Content-Type: application/json\r\n" MG_NO_CACHE_HEADERS @@ -453,7 +454,6 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) { struct mg_http_serve_opts opts; memset(&opts, 0, sizeof(opts)); opts.fs = &mg_fs_packed; - mg_mem_files = mg_packed_files; mg_http_serve_file(c, hm, "/dashboard.html", &opts); } else { struct mg_dash_custom_handler *ch = dash->custom_handlers; diff --git a/tutorials/core/embedded-filesystem/packed_fs.c b/tutorials/core/embedded-filesystem/packed_fs.c index df1b6555..87fccb45 100644 --- a/tutorials/core/embedded-filesystem/packed_fs.c +++ b/tutorials/core/embedded-filesystem/packed_fs.c @@ -43,7 +43,7 @@ static const unsigned char v1[] = { 101, 61, 34, 109, 111, 100, 117, 108, 101, 34, 32, 115, // e="module" s 114, 99, 61, 34, 109, 97, 105, 110, 46, 106, 115, 34, // rc="main.js" 62, 60, 47, 115, 99, 114, 105, 112, 116, 62, 10, 60, // >.< - 47, 104, 116, 109, 108, 62, 10,// /html>. + 47, 104, 116, 109, 108, 62, 10, 0 // /html>. }; static const unsigned char v2[] = { 39, 117, 115, 101, 32, 115, 116, 114, 105, 99, 116, 39, // 'use strict' @@ -269,7 +269,7 @@ static const unsigned char v2[] = { 108, 111, 97, 100, 32, 61, 32, 40, 41, 32, 61, 62, // load = () => 32, 114, 101, 110, 100, 101, 114, 40, 104, 40, 65, 112, // render(h(Ap 112, 41, 44, 32, 100, 111, 99, 117, 109, 101, 110, 116, // p), document - 46, 98, 111, 100, 121, 41, 59, 10,// .body);. + 46, 98, 111, 100, 121, 41, 59, 10, 0 // .body);. }; static const unsigned char v3[] = { 118, 97, 114, 32, 101, 44, 110, 44, 95, 44, 116, 44, // var e,n,_,t, @@ -1371,7 +1371,7 @@ static const unsigned char v3[] = { 97, 115, 32, 117, 115, 101, 68, 101, 98, 117, 103, 86, // as useDebugV 97, 108, 117, 101, 44, 95, 101, 32, 97, 115, 32, 117, // alue,_e as u 115, 101, 69, 114, 114, 111, 114, 66, 111, 117, 110, 100, // seErrorBound - 97, 114, 121, 125, 59, 10,// ary};. + 97, 114, 121, 125, 59, 10, 0 // ary};. }; static const unsigned char v4[] = { 42, 32, 123, 32, 98, 111, 120, 45, 115, 105, 122, 105, // * { box-sizi @@ -1526,14 +1526,14 @@ static const unsigned char v4[] = { 100, 116, 104, 58, 32, 57, 50, 48, 112, 120, 41, 32, // dth: 920px) 123, 32, 46, 114, 111, 119, 32, 46, 99, 111, 108, 32, // { .row .col 123, 32, 119, 105, 100, 116, 104, 58, 32, 49, 48, 48, // { width: 100 - 37, 59, 32, 125, 32, 125, 10,// %; } }. + 37, 59, 32, 125, 32, 125, 10, 0 // %; } }. }; const struct mg_mem_file mg_packed_files[] = { - {"/web_root/index.html", v1, sizeof(v1), 1730991857}, - {"/web_root/main.js", v2, sizeof(v2), 1730991857}, - {"/web_root/preact.min.js", v3, sizeof(v3), 1730991857}, - {"/web_root/style.css", v4, sizeof(v4), 1730991857}, + {"/web_root/index.html", v1, sizeof(v1) - 1, 1730991857}, + {"/web_root/main.js", v2, sizeof(v2) - 1, 1730991857}, + {"/web_root/preact.min.js", v3, sizeof(v3) - 1, 1730991857}, + {"/web_root/style.css", v4, sizeof(v4) - 1, 1730991857}, {NULL, NULL, 0, 0} }; diff --git a/tutorials/device-dashboard/full/dashboard.c b/tutorials/device-dashboard/full/dashboard.c index 545271ff..9dcbc7b0 100644 --- a/tutorials/device-dashboard/full/dashboard.c +++ b/tutorials/device-dashboard/full/dashboard.c @@ -190,6 +190,7 @@ void mg_dash_init(struct mg_mgr *mgr) { // Require authentication dash.authenticate = authenticate; + mg_mem_files = mg_packed_files; mg_http_listen(mgr, MG_HTTP_ADDR, mg_dash_ev_handler, &dash); } diff --git a/tutorials/device-dashboard/minimal/dashboard.c b/tutorials/device-dashboard/minimal/dashboard.c index b158e3dc..9876ea6e 100644 --- a/tutorials/device-dashboard/minimal/dashboard.c +++ b/tutorials/device-dashboard/minimal/dashboard.c @@ -38,6 +38,7 @@ static struct mg_field_set field_set_status = { void mg_dash_init(struct mg_mgr *mgr) { static struct mg_dash dash; // Important: keep it static! MG_DASH_ADD_FIELD_SET(&dash, &field_set_status); + mg_mem_files = mg_packed_files; mg_http_listen(mgr, MG_HTTP_ADDR, mg_dash_ev_handler, &dash); }