Add admin serial settings view

This commit is contained in:
2026-09-07 20:12:33 +02:00
parent c73674cda2
commit 5a2aa0d4d8
20 changed files with 612 additions and 25 deletions
+28 -1
View File
@@ -37,11 +37,13 @@ struct sock_db { bool ws_handshake_done; esp_err_t (*ws_handler)(httpd_req_t *);
struct httpd_req_aux { struct sock_db *sd; char *scratch; size_t scratch_cur_size, remaining_len;
unsigned req_hdrs_count, resp_hdrs_count; bool ws_handshake_detect;
struct resp_hdr { const char *field, *value; } *resp_hdrs; };
struct httpd_data { struct { unsigned max_resp_headers; } config; };
struct httpd_data { struct { unsigned max_resp_headers, max_uri_handlers; void *uri_match_fn; } config;
httpd_uri_t **hd_calls; };
esp_err_t httpd_ws_respond_server_handshake(httpd_req_t *, const char *);
"""
admin = "--admin" in sys.argv
settings = "--settings" in sys.argv
if admin:
HEADERS["esp_system.h"] = "#pragma once\nvoid esp_restart(void);\n"
HEADERS["esp_heap_caps.h"] = """#pragma once
@@ -73,8 +75,10 @@ extracted = """
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "esp_httpd_priv.h"
#define ESP_LOGD(...) ((void)0)
#define ESP_LOGW(...) ((void)0)
#define MIN(a,b) ((a) < (b) ? (a) : (b))
static bool httpd_valid_req(httpd_req_t *r) { return r && r->aux; }
static size_t strlcpy(char *d, const char *s, size_t n) {
@@ -88,6 +92,9 @@ for name in ["httpd_req_get_hdr_value_len", "httpd_req_get_hdr_value_str"]:
extracted += function(txrx[txrx.index("esp_err_t httpd_resp_set_hdr"):], "httpd_resp_set_hdr")
extracted += "\n" + function(txrx[txrx.index("static size_t httpd_recv_pending"):], "httpd_recv_pending")
extracted += "\nsize_t host_read_pending(httpd_req_t *r, char *out, size_t n) { return httpd_recv_pending(r, out, n); }\n"
if settings:
uri_source = (idf / 'components/esp_http_server/src/httpd_uri.c').read_text()
extracted += '\n' + function(uri_source[uri_source.index('esp_err_t httpd_unregister_uri_handler'):], 'httpd_unregister_uri_handler')
with tempfile.TemporaryDirectory(prefix="web-cookie-auth-") as directory:
tmp = pathlib.Path(directory)
@@ -96,12 +103,32 @@ with tempfile.TemporaryDirectory(prefix="web-cookie-auth-") as directory:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text)
(tmp / "installed_httpd.c").write_text(extracted)
if settings:
# Compile exact production handler/helpers and nonblocking snapshot body.
server_source = (ROOT / 'src/web_server.c').read_text()
service_source = (ROOT / 'src/serial_service.c').read_text()
config_source = (ROOT / 'src/serial_config.c').read_text()
settings_source = function(service_source, 'serial_service_get_snapshot') + '\n'
for name in ('data_bits', 'parity', 'stop_bits', 'flow_control', 'dtr_behavior'):
settings_source += function(config_source[config_source.index('const char *serial_config_' + name + '_to_string'):], 'serial_config_' + name + '_to_string') + '\n'
for name in ('set_common_headers', 'send_plain_error', 'authorize_or_respond', 'safe_string', 'serial_settings_handler'):
settings_source += function(server_source, name) + '\n'
(tmp / 'settings_production.h').write_text(settings_source)
sources = [HERE / "test.c", tmp / "installed_httpd.c"]
sources += [ROOT / "src" / name for name in ["web_session_store.c", "web_auth_parse.c", "web_cookie_auth.c", "web_httpd_adapter.c"]]
if admin:
sources += [ROOT / "src" / name for name in ["web_admin_tickets.c", "web_admin_transport.c"]]
if settings:
adapter = ROOT / 'src/web_httpd_adapter.c'
sources.remove(adapter)
subprocess.run(['cc', '-std=c11', '-D_GNU_SOURCE', '-Wall', '-Wextra', '-Werror',
'-Dmalloc=settings_malloc', '-Dfree=settings_free',
'-I' + str(tmp), '-I' + str(ROOT / 'src'), '-c', str(adapter),
'-o', str(tmp / 'adapter.o')], check=True, timeout=30)
sources.append(tmp / 'adapter.o')
subprocess.run(["cc", "-std=c11", "-Wall", "-Wextra", "-Werror", "-g", "-DHOST_OPENSSL",
*(["-DHOST_ADMIN"] if admin else []),
*(["-DHOST_SETTINGS"] if settings else []),
"-I" + str(tmp), "-I" + str(ROOT / "src"), *map(str, sources), "-lcrypto",
"-o", str(tmp / "test")], check=True, timeout=30)
subprocess.run([str(tmp / "test")], check=True, timeout=20)