/* SPDX-License-Identifier: GPL-3.0-only */ /* Authenticated HTTPS administration foundation. */ #pragma once #include #include #include "esp_err.h" #ifdef __cplusplus extern "C" { #endif typedef struct { uint64_t starts; uint64_t start_failures; uint64_t stops; uint64_t requests; uint64_t authenticated_requests; uint64_t authentication_failures; uint64_t root_requests; uint64_t status_requests; uint64_t ticket_requests; uint64_t asset_requests; uint64_t response_errors; } web_server_counters_t; typedef struct { bool initialized; bool running; bool transitioning; uint16_t port; esp_err_t last_error; esp_err_t serial_transport_error; web_server_counters_t counters; } web_server_snapshot_t; /* Initialize runtime state without requiring valid certificate material. */ esp_err_t web_server_init(void); typedef struct { uint32_t generation; bool running; bool transitioning; bool controllable; } web_server_management_snapshot_t; /* Zero-wait, secret-free projection; controllable excludes failed cleanup and * exhausted generations. No HTTPD work or owner wait is performed. */ esp_err_t web_server_get_management_snapshot(web_server_management_snapshot_t *snapshot); /* Conditional lifecycle admission under the canonical server mutex. Call only * off HTTPD, after caller-owned authorization and bounded ACK handoff. These * APIs do not authenticate, acknowledge, cancel on revocation, or bound HTTPD * shutdown time. Restart reserves the lifecycle through stop and start; a failed * stop never starts another server. Stale/exhausted/unclean state rejects without * side effects. Canonical stop/start below remain the recovery path. */ esp_err_t web_server_stop_current(uint32_t expected_generation); esp_err_t web_server_restart_current(uint32_t expected_generation); /* Reserves this HTTPS generation before canonical whole-device esp_restart(). * Admission cannot be cancelled; normally does not return. Same caller rules. */ esp_err_t web_server_reboot_current(uint32_t expected_generation); /* Combined identity/service owner operation, off HTTPD only. Nonzero expected * generations select healthy running conditional rotation; both zero select CLI. * reset is CLI-only and starts a stopped service; ordinary rotation leaves it stopped. * committed reports irreversible NVS publication even when stop/start later fails. * Reservation covers generation checks, crypto/commit and canonical stop/start. */ esp_err_t web_server_replace_identity(uint32_t expected_service_generation, uint32_t expected_identity_generation, bool reset, bool *committed); /* Start one TLS-only server on all active network interfaces. * Start/stop may wait for HTTPD; never call from its task or queued callbacks. */ esp_err_t web_server_start(void); esp_err_t web_server_stop(void); esp_err_t web_server_get_snapshot(web_server_snapshot_t *snapshot); esp_err_t web_server_clear_counters(void); #ifdef __cplusplus } #endif