Commit Graph

22386 Commits

Author SHA1 Message Date
J. Nick Koston
d30b321f7c Merge branch 'web_server_use_arg_api' into integration 2026-02-11 19:16:27 -06:00
J. Nick Koston
220c2acf0e Check for ESP_OK or ESP_ERR_HTTPD_RESULT_TRUNC explicitly in query_has_key
Instead of treating any non-ESP_ERR_NOT_FOUND result as key-present,
explicitly check for the two success codes. This avoids false positives
from unexpected error codes like ESP_ERR_INVALID_ARG.
2026-02-11 19:15:43 -06:00
J. Nick Koston
1a926da7b4 Check for ESP_OK or ESP_ERR_HTTPD_RESULT_TRUNC explicitly in query_has_key
Instead of treating any non-ESP_ERR_NOT_FOUND result as key-present,
explicitly check for the two success codes. This avoids false positives
from unexpected error codes like ESP_ERR_INVALID_ARG.
2026-02-11 19:15:35 -06:00
J. Nick Koston
961b830df5 Merge branch 'web_server_use_arg_api' into integration 2026-02-11 19:07:31 -06:00
J. Nick Koston
52461f10e7 Use httpd_req_get_url_query_len instead of strlen for query length
The parsed URL already has the query length available via the httpd API.
Avoids redundant strlen over the query string.
2026-02-11 19:06:28 -06:00
J. Nick Koston
2348ad2a03 Access URL query string directly from req->uri instead of stack copy
The query string already lives in req->uri. Access it via strchr('?')
instead of copying into a 513-byte stack buffer via httpd_req_get_url_query_str.
This is the same pattern url_to() uses — http_parser identifies URI
components by offset/length without modifying the source string.

Eliminates 513 bytes of stack usage on the httpd task, leaving only
the 128-byte value extraction buffer in query_key_value.
2026-02-11 19:06:02 -06:00
J. Nick Koston
94cab38206 Access URL query string directly from req->uri instead of stack copy
The query string already lives in req->uri. Access it via strchr('?')
instead of copying into a 513-byte stack buffer via httpd_req_get_url_query_str.
This is the same pattern url_to() uses — http_parser identifies URI
components by offset/length without modifying the source string.

Eliminates 513 bytes of stack usage on the httpd task, leaving only
the 128-byte value extraction buffer in query_key_value.
2026-02-11 19:05:52 -06:00
J. Nick Koston
1ea653e6ab Merge branch 'json_web_server_stack' into integration 2026-02-11 19:02:10 -06:00
J. Nick Koston
aa870483f1 Reduce SerializationBuffer stack size from 768 to 512 bytes
768 bytes on the httpd task stack contributes to stack overflow when
combined with other stack-allocated buffers (query string parsing, etc.).
512 bytes still covers all typical JSON payloads (sensors ~200B, lights
~170B, climate ~500-700B). Only extreme edge cases with 40+ options
trigger heap fallback.
2026-02-11 18:58:28 -06:00
J. Nick Koston
181fb4f8ac Reduce SerializationBuffer stack size from 768 to 512 bytes
768 bytes on the httpd task stack contributes to stack overflow when
combined with other stack-allocated buffers (query string parsing, etc.).
512 bytes still covers all typical JSON payloads (sensors ~200B, lights
~170B, climate ~500-700B). Only extreme edge cases with 40+ options
trigger heap fallback.
2026-02-11 18:57:53 -06:00
J. Nick Koston
9ef0ad3f9d Merge branch 'web_server_use_arg_api' into integration 2026-02-11 18:55:06 -06:00
J. Nick Koston
2b5bd961ef Fix stack overflow: use small stack buffer with heap fallback in query_key_value
Revert direct req->uri access (unsafe — ESP-IDF uses parsed offsets,
not strchr). Instead fix the root cause: query_key_value used a full
CONFIG_HTTPD_MAX_URI_LEN+1 (513 byte) stack buffer while
search_query_sources had another 513 byte buffer on the stack
simultaneously, totaling ~1KB on the httpd thread's limited stack.

Use SmallBufferWithHeapFallback<128> for the value extraction buffer.
128 bytes covers typical parameter values on stack; longer values
(e.g. base64 IR data) fall back to heap.
2026-02-11 18:53:58 -06:00
J. Nick Koston
5a88bb6d8a Fix stack overflow: access URL query directly from req->uri
search_query_sources was copying the URL query string into a 513-byte
stack buffer, then query_key_value added another 513-byte buffer for
the extracted value — 1026 bytes simultaneously on the httpd thread's
limited stack, causing a crash in lwip_select.

The query string already lives in req->uri after the '?'. Access it
directly via pointer instead of copying, eliminating one buffer entirely.
2026-02-11 18:51:45 -06:00
J. Nick Koston
1bb6b24a1a Merge branch 'web_server_use_arg_api' into integration 2026-02-11 18:39:53 -06:00
J. Nick Koston
53345724f2 Use fixed stack buffer for query strings bounded by CONFIG_HTTPD_MAX_URI_LEN
Query strings cannot exceed the max URI length, so SmallBufferWithHeapFallback
is unnecessary. Use a plain stack array instead for zero heap allocation.
2026-02-11 18:38:25 -06:00
J. Nick Koston
92d800412a Skip empty post_query in search_query_sources; reuse find_query_value_ in getParam
- Add early return for empty post_query (common GET request path)
- Refactor getParam to use find_query_value_ instead of duplicating search logic
- Remove now-unused request_get_url_query (and its heap allocation)
- Remove unused std::string overload of query_key_value
2026-02-11 18:35:10 -06:00
J. Nick Koston
e57612d522 Avoid heap allocation for URL query in hasArg/arg
Replace request_get_url_query (returns std::string) with inline
httpd_req_get_url_query_str into a SmallBufferWithHeapFallback
stack buffer. Typical query strings (<256 bytes) now use zero
heap allocations for parameter lookups.
2026-02-11 18:27:55 -06:00
J. Nick Koston
f0828928b4 Extract search_query_sources to deduplicate hasArg/find_query_value_
Both methods iterated post_query_ then url_query with the same
pattern. Extracted a file-local template that takes a callback,
avoiding duplicated request_get_url_query heap allocation logic.
2026-02-11 18:26:13 -06:00
J. Nick Koston
e42cc2e394 Add query_has_key for efficient hasArg without string allocation
hasArg only needs to know if a key exists, not its value.
query_has_key uses a 1-byte buffer and checks the return code
from httpd_query_key_value — no url_decode, no std::string.
2026-02-11 18:23:38 -06:00
J. Nick Koston
1d70341da9 Merge branch 'web_server_use_arg_api' into integration 2026-02-11 18:18:12 -06:00
J. Nick Koston
592d5ec24c Restore hasArg guard in parse_string_param_
Empty string is a valid value for string params (e.g. select
options). Must use hasArg to distinguish missing from empty.
2026-02-11 18:17:24 -06:00
J. Nick Koston
91a0b0989e Simplify captive_portal lambda capture
Capture auto type directly and use c_str() overload of
save_wifi_sta. Works on both std::string and Arduino String.
2026-02-11 18:14:46 -06:00
J. Nick Koston
f35dfefdf3 Remove readability-redundant-string-cstr NOLINTs from captive_portal
Use const auto& to bind arg() result directly. Construct
std::string only in deferred lambda capture where ownership
is needed.
2026-02-11 18:13:32 -06:00
J. Nick Koston
892804e02e Remove remaining readability-redundant-string-cstr NOLINTs
Use const auto& to bind arg() result directly, avoiding
unnecessary std::string intermediate copies. Construct
std::string only where needed (lambda capture, setter call).
2026-02-11 18:12:47 -06:00
J. Nick Koston
5585b5967e Avoid std::string copy in date/time/datetime handlers
Use const auto& to bind directly to arg() result (std::string on
IDF, Arduino String on Arduino) and pass c_str()/length() to the
setter. No intermediate std::string copy needed.
2026-02-11 18:11:49 -06:00
J. Nick Koston
73867c62be Pass c_str() and size() directly to date/time/datetime setters
These setters have (const char*, size_t) overloads that do the
actual work. Skip the std::string& overload indirection.
2026-02-11 18:10:43 -06:00
J. Nick Koston
a6579dc2f1 Pass c_str() and size() directly to date/time/datetime setters
These setters have (const char*, size_t) overloads that do the
actual work. Skip the std::string& overload indirection.
2026-02-11 18:10:36 -06:00
J. Nick Koston
f4493100e3 Merge branch 'web_server_use_arg_api' into integration 2026-02-11 18:09:35 -06:00
J. Nick Koston
920f84fa1d Eliminate double lookups in parse_string_param_ and date/time/datetime handlers
- parse_string_param_: use arg() and check empty instead of hasArg+arg
- date/time/datetime: inline arg() call to avoid redundant hasArg+parse_string_param_ triple lookup
2026-02-11 18:08:23 -06:00
J. Nick Koston
d73bd9997e Merge branch 'web_server_use_arg_api' into integration 2026-02-11 18:03:52 -06:00
J. Nick Koston
c2bb55ff5d Add NOLINT for length() > 0 cross-platform check
Arduino String has isEmpty() not empty(). Using length() > 0
works on both std::string and Arduino String.
2026-02-11 18:03:32 -06:00
J. Nick Koston
c6b51d3434 Fix clang-tidy: disambiguate overloaded climate setters
ClimateCall has overloaded set_target_temperature*(float) and
set_target_temperature*(optional<float>), so the compiler can't
infer NumT. Use static_cast to select the float overload.
2026-02-11 18:02:56 -06:00
J. Nick Koston
598978de45 Fix clang-tidy: disambiguate overloaded climate setters
ClimateCall has overloaded set_target_temperature*(float) and
set_target_temperature*(optional<float>), so the compiler can't
infer NumT. Use static_cast to select the float overload.
2026-02-11 18:02:23 -06:00
J. Nick Koston
c727819b23 Merge branch 'web_server_use_arg_api' into integration 2026-02-11 17:58:09 -06:00
J. Nick Koston
f638b65f1e Fix Arduino build: use length() instead of empty()
Arduino String has isEmpty() not empty(). Use length() > 0
which works on both std::string and Arduino String.
2026-02-11 17:57:49 -06:00
J. Nick Koston
0a99abd63f Fix Arduino build: use length() instead of empty()
Arduino String has isEmpty() not empty(). Use length() > 0
which works on both std::string and Arduino String.
2026-02-11 17:57:39 -06:00
J. Nick Koston
ca92601b5a Merge branch 'web_server_use_arg_api' into integration 2026-02-11 17:56:35 -06:00
J. Nick Koston
f92725f76e Eliminate double query lookups and unify numeric parse helpers
- Mark find_query_value_ as const
- Remove redundant hasArg() guards where parse_number() already
  handles empty strings (returns nullopt)
- Use !empty() instead of hasArg() for parse_bool_param_
- Merge parse_float_param_ and parse_int_param_ into single
  parse_num_param_ template
- Combine missing/empty checks for IR data parameter
2026-02-11 17:54:56 -06:00
J. Nick Koston
8b1150f21f Merge remote-tracking branch 'upstream/dev' into integration 2026-02-11 17:43:26 -06:00
J. Nick Koston
2a89088bc3 Merge branch 'dev' into web_server_use_arg_api 2026-02-11 17:43:10 -06:00
J. Nick Koston
ae42bfa404 [web_server_idf] Remove std::string temporaries from multipart header parsing (#13940) 2026-02-11 17:42:33 -06:00
J. Nick Koston
fecb145a71 [web_server_idf] Revert multipart upload buffer back to heap to fix httpd stack overflow (#13941) 2026-02-11 17:42:18 -06:00
J. Nick Koston
ffd778356b Merge branch 'web_server_use_arg_api' into integration 2026-02-11 17:37:24 -06:00
J. Nick Koston
db831ebee0 Fix clang-tidy: use const auto& for arg() return value
On Arduino, arg() returns const String&, so auto copies unnecessarily.
const auto& binds to the reference on Arduino and extends the temporary
lifetime on IDF.
2026-02-11 17:37:09 -06:00
J. Nick Koston
36e970dd8c Merge branch 'web_server_use_arg_api' into integration 2026-02-11 17:36:19 -06:00
J. Nick Koston
4f3c95ced2 [web_server] Switch from getParam to arg API to eliminate heap allocations
Switch all web_server callers from getParam()/hasParam() to arg()/hasArg().
Both APIs exist on Arduino ESPAsyncWebServer and our IDF implementation.

On the IDF side, getParam() allocated a new AsyncWebParameter on the heap
for every successful lookup, cached it in a vector, and required cleanup
in the destructor. No caller ever held the pointer or called getParam
twice with the same name - every use was just getParam("x")->value()
immediately.

Rewrite IDF arg()/hasArg() to call query_key_value() directly, bypassing
getParam entirely. The linker strips the now-unreferenced getParam,
AsyncWebParameter, and cache machinery.

Saves ~348 bytes flash on ESP32-IDF, ~272 bytes on ESP8266 Arduino.
2026-02-11 17:33:11 -06:00
J. Nick Koston
1401e55251 Revert "Revert "[web_server_idf] Remove std::string temporaries from multipart header parsing""
This reverts commit c03e38d688.
2026-02-11 17:04:34 -06:00
J. Nick Koston
464fcb7480 Merge branch 'revert_stack_buffer_multipart' into integration 2026-02-11 17:04:22 -06:00
J. Nick Koston
dbe8e39aa9 [web_server_idf] Move multipart upload buffer back to heap to fix httpd stack overflow
The 1460-byte MULTIPART_CHUNK_SIZE buffer was moved from heap to stack
in #13549, but the httpd task stack is only ~4096-5632 bytes. This
causes a stack overflow crash when processing OTA uploads, especially
on configs with BLE components that add additional stack pressure.

Move it back to heap since this buffer is only used during OTA uploads
(not a hot path), so heap fragmentation is not a concern here.

Fixes stack overflow: "A stack overflow in task httpd has been detected"
2026-02-11 17:03:07 -06:00
J. Nick Koston
c03e38d688 Revert "[web_server_idf] Remove std::string temporaries from multipart header parsing"
This reverts commit f6bb54486d.
2026-02-11 16:49:51 -06:00