httpd: scan the upload preamble with a register cursor

The preamble scan cursor and the buffered-length parameter carry no
state between calls, so they do not need static xdata slots. As plain
locals the compiler places both in registers, trimming 64 bytes of
BANK1 code and two bytes of xdata.

The offsets shared by config_take() stay static: direct data space is
fully allocated on machines like the SWTGW218AS, so plain locals there
add overlay bytes that no longer link, and xdata-class locals spill
three temporaries into direct space while growing the code by roughly
120 bytes. Document pre_acc, whose accumulation across TCP segments is
why it must remain global.
This commit is contained in:
bloqaudio
2026-08-30 04:09:30 -05:00
parent be7796a22c
commit b63117ba6c
+12 -9
View File
@@ -49,6 +49,7 @@ __xdata uint8_t boundary[72];
__xdata uint8_t config_upload;
__xdata uint8_t config_buf[CONFIG_UPLOAD_BUF];
__xdata uint16_t cfg_pos, cfg_hdr, cfg_body, cfg_end, cfg_last;
// part-header bytes buffered so far; accumulates across TCP segments
__xdata uint16_t pre_acc;
__xdata uint8_t cfg_bl;
__xdata uint8_t * __xdata content_type = 0;
@@ -381,20 +382,22 @@ static uint8_t config_take(void)
// unlike scan_header(), keeps no auth state, so it may run on every buffered segment
static uint16_t preamble_payload_start(__xdata uint16_t n)
static uint16_t preamble_payload_start(uint16_t n)
{
for (cfg_pos = 0; cfg_pos + 24 <= n; cfg_pos++) {
if (strstart(&config_buf[cfg_pos], "application/octet-stream"))
uint16_t pos;
for (pos = 0; pos + 24 <= n; pos++) {
if (strstart(&config_buf[pos], "application/octet-stream"))
break;
}
if (cfg_pos + 24 > n)
if (pos + 24 > n)
return 0;
cfg_pos += 24;
while (cfg_pos + 3 < n && !strstart(&config_buf[cfg_pos], "\r\n\r\n"))
cfg_pos++;
if (cfg_pos + 3 >= n)
pos += 24;
while (pos + 3 < n && !strstart(&config_buf[pos], "\r\n\r\n"))
pos++;
if (pos + 3 >= n)
return 0;
return cfg_pos + 4;
return pos + 4;
}