Minimise build size

This commit is contained in:
cpq committed 2026-10-10 12:25:44 +01:00
1 parent 300011a882
commit aae179177c
12 files changed
+92 -65

No files matched your search

+21 -22
View File
@@ -8842,8 +8842,6 @@ static void onstatechange(struct mg_tcpip_if *ifp) {
mg_tcpip_arp_request(ifp, ifp->gw, NULL); // unsolicited GW ARP request
} else if (ifp->state == MG_TCPIP_STATE_UP) {
srand((unsigned int) mg_millis());
} else if (ifp->state == MG_TCPIP_STATE_DOWN) {
MG_ERROR(("Link down"));
}
mg_tcpip_call(ifp, MG_TCPIP_EV_STATE_CHANGE, &ifp->state);
}
@@ -13525,8 +13523,10 @@ char *mg_mprintf(const char *fmt, ...) {
}
void mg_pfn_stdout(char c, void *param) {
#if MG_ENABLE_POSIX_FS
putchar(c);
(void) param;
#endif
(void) param, (void) c;
}
static size_t print_ip4(void (*out)(char, void *), void *arg, uint8_t *p) {
@@ -19901,9 +19901,6 @@ static PORTABLE_8439_DECL void poly1305_finish(poly1305_context *ctx,
// ******* END: poly1305-donna/poly1305-donna.h ********
// ******* BEGIN: chacha-portable.c ********
#include <assert.h>
#include <string.h>
// this is a fresh implementation of chacha20, based on the description in
// rfc8349 it's such a nice compact algorithm that it is easy to do. In
// relationship to other c implementation this implementation:
@@ -26539,6 +26536,7 @@ struct mg_str mg_url_pass(const char *url) {
// Not using memset for zeroing memory, cause it can be dropped by compiler
// See https://github.com/cesanta/mongoose/pull/1265
void mg_bzero(volatile unsigned char *buf, size_t len) {
@@ -26681,22 +26679,21 @@ uint16_t mg_crc16(uint16_t crc, const char *buf, size_t len) {
return (uint16_t) ~c;
}
static int isbyte(int n) {
return n >= 0 && n <= 255;
}
static int parse_net(const char *spec, uint32_t *net, uint32_t *mask) {
int n, a, b, c, d, slash = 32, len = 0;
if ((sscanf(spec, "%d.%d.%d.%d/%d%n", &a, &b, &c, &d, &slash, &n) == 5 ||
sscanf(spec, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4) &&
isbyte(a) && isbyte(b) && isbyte(c) && isbyte(d) && slash >= 0 &&
slash < 33) {
len = n;
*net = ((uint32_t) a << 24) | ((uint32_t) b << 16) | ((uint32_t) c << 8) |
(uint32_t) d;
*mask = slash ? (uint32_t) (0xffffffffU << (32 - slash)) : (uint32_t) 0;
// Parse "IP" or "IP/BITS" into net and mask. The whole spec must be valid
static bool parse_net(struct mg_str spec, uint32_t *net, uint32_t *mask) {
struct mg_str caps[3], ip = spec, bits = mg_str("32");
struct mg_addr addr;
uint8_t n = 0;
if (mg_match(spec, mg_str("*/*"), caps)) ip = caps[0], bits = caps[1];
// ip.len == 0 check: mg_aton() parses an empty string as 0.0.0.0
if (ip.len == 0 || !mg_aton(ip, &addr) || addr.is_ip6 ||
!mg_str_to_num(bits, 10, &n, sizeof(n)) || n > 32) {
return false;
}
return len;
memcpy(net, addr.addr.ip, sizeof(*net));
*net = mg_ntohl(*net);
*mask = n ? (uint32_t) (0xffffffffU << (32 - n)) : (uint32_t) 0;
return true;
}
int mg_check_ip_acl(struct mg_str acl, struct mg_addr *remote_ip) {
@@ -26710,7 +26707,9 @@ int mg_check_ip_acl(struct mg_str acl, struct mg_addr *remote_ip) {
while (mg_span(acl, &entry, &acl, ',')) {
uint32_t net, mask;
if (entry.buf[0] != '+' && entry.buf[0] != '-') return -1;
if (parse_net(&entry.buf[1], &net, &mask) == 0) return -2;
if (!parse_net(mg_str_n(entry.buf + 1, entry.len - 1), &net, &mask)) {
return -2;
}
if ((mg_ntohl(remote_ip4) & mask) == net) allowed = entry.buf[0];
}
}