Init tls in dash, use dash in u5-usb

This commit is contained in:
cpq committed 2026-11-27 23:53:56 +00:00
1 parent b45e0fbcb4
commit e9845a7dac
10 files changed
+80 -49

No files matched your search

+7
View File
@@ -1,6 +1,7 @@
#include "dash.h"
#include "http.h"
#include "ota.h"
#include "tls.h"
#include "util.h"
#define MG_NO_CACHE_HEADERS "Cache-Control: no-cache\r\n"
@@ -559,6 +560,12 @@ void mg_dash_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_OPEN) {
d->dash = dash;
// c->is_hexdumping = 1;
} else if (ev == MG_EV_ACCEPT && c->is_tls) {
struct mg_tls_opts opts;
memset(&opts, 0, sizeof(opts));
opts.cert = dash->tls_cert, opts.key = dash->tls_key;
if (dash->tls_cert.len == 0) c->is_closing = 1; // No cert: refuse
else mg_tls_init(c, &opts);
} else if (ev == MG_EV_CLOSE && c->is_listening) {
mg_dash_delete_users(c->mgr, dash);
} else if (ev == MG_EV_HTTP_HDRS && d->marker == 0) {
+3 -1
View File
@@ -18,7 +18,7 @@
#define MG_MODBUS_ADDR "tcp://0.0.0.0:8502"
#else
#define MG_HTTP_ADDR "http://0.0.0.0:80"
#define MG_HTTPS_ADDR "http://0.0.0.0:443"
#define MG_HTTPS_ADDR "https://0.0.0.0:443"
#define MG_MODBUS_ADDR "tcp://0.0.0.0:502"
#endif
#endif
@@ -99,6 +99,8 @@ struct mg_dash {
// - The returned directory must be nonempty and must not contain ',' or '=',
// because it is used as an mg_http_serve_opts::root_dir mapping target.
bool (*files_dir)(const struct mg_dash_user *u, char *buf, size_t len);
struct mg_str tls_cert; // HTTPS listener certificate, PEM. Empty: no HTTPS
struct mg_str tls_key; // HTTPS listener private key, PEM
};
#define MG_DASH_ADD_FIELD_SET(dash_, set_) \