Commit Graph
21 Commits
Author SHA1 Message Date
Brad ArantandClaude Sonnet 5 bf6810b781 Rebuild CGIFormData on Parser/StreamReader, fix a 2-byte-lookahead bug
CGIFormData now inherits Parser instead of MString and parses a CGI
request body (urlencoded or multipart/form-data) resumably against the
shared StreamReader, exposing the result via operator[] - matching every
other Parser in this redesign. multipart/form-data reuses IMFBoundary and
IMFHeader via checkParse() (chained through the same StreamReader) for
each part's boundary line and header block; urlencoded bodies wait for
the full Content-Length before delegating to the existing
CGIFormattedData parser. File-upload parts (Content-Disposition with a
filename= parameter) are recognized and skipped, matching this
codebase's convention that uploads get a separate mechanism.

Values are stored under an indexed "name:N" key (N = 0-based occurrence
count for that name), matching the :N-suffix convention JetCore's
Tag::getVariable already applies to its $[:name] CGI variable syntax
(defaulting to :0) - this also naturally supports repeated field names
(checkboxes, multi-select). operator[] applies the same :0 default so a
bare name still works when called directly, not just through that
convention layer.

Two real resumability bugs found and fixed via a byte-at-a-time test
(feeding one byte per StreamReader::feed() call, the harshest possible
fragmentation):
- CGIFormData's opening boundary marker ("--boundary", no leading CRLF
  per RFC 2046 for the first boundary) crammed "find+consume the marker"
  and "disambiguate -- vs CRLF" into one state; when the disambiguation
  needed more data, INCOMPLETE was returned without recording that the
  marker was already consumed, so retrying re-searched for it past where
  it had already been consumed, silently skipping content forever. Split
  into two states (INIT / OPENING_TAIL), the same fix already applied
  once to IMFBoundary's PREFIX/TAIL split.
- IMFHeader's FIELD state checked eod() (a 1-byte availability check)
  immediately before an ifNext("\r\n") call that needs 2 bytes - a lone
  trailing \r with no \n yet available was wrongly treated as malformed
  instead of "wait for more data". Fixed to check getLength() < 2.

Verified via a dedicated test (64 assertions total across this and the
earlier Parser/StreamReader test) covering urlencoded, multipart with a
skipped file upload, and the byte-at-a-time stress case - plus a real
end-to-end run through jet-2.0 with a simulated CGI multipart POST
request (see the matching JetCore commit).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-23 15:07:09 -07:00
Brad ArantandClaude Sonnet 5 a033cc6718 Add StreamReader and rebuild Parser/LineParser/IMFHeader/IMFBoundary on it
Introduces StreamReader to accumulate socket data delivered in arbitrary
chunks into one buffer, so a Parser can build an object (a line, a header
block, a MIME boundary) that spans any number of packets without losing
its place. Parser is redesigned around this: no longer inherits MString
(was redundant with its own buffer member), takes a StreamReader&, and
drives a resumable COMPLETE/INCOMPLETE/DATA_AVAIL state-machine protocol
via doParse(). LineParser, IMFHeader, and IMFBoundary are rewritten as
real, working resumable parsers against the shared buffer instead of the
previous non-compiling stubs (mismatched constructors/return types, a
syntax error, checkParse() never implemented).

IMFFormData is left as the stub it already was, just restored to
compiling against the new IMFHeader signature - fully wiring it up needs
IMFMultipart/IMFText migrated to StreamReader too, out of scope here.

Verified with real runtime tests (not just compilation) covering data
split mid-line, mid-CRLF, mid-header-fold, and mid-boundary-marker across
separate feed() calls, plus StreamReader::compact(). Along the way fixed
a header-value bug (space after ':' wasn't skipped) and a double
cursor-offset subtraction bug in two places caused by forgetting that
ZString::getLength() is already cursor-relative, not the raw buffer size.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-23 14:25:58 -07:00
Brad Arant d415e0abd3 Still working out parsing buffer stuff. 2025-12-18 15:40:37 -08:00
Brad Arant ccfab5aecf Still working out parsing buffer stuff. 2025-12-17 17:07:14 -08:00
Brad Arant 9cd8381845 significant work on cookies and cgi formdata variables. 2025-03-18 16:46:20 -07:00
Brad Arant bd5223ca36 more cgi processing multiform work. 2025-03-17 16:45:34 -07:00
Brad Arant 2866056072 more IMF work. 2025-03-11 16:59:16 -07:00
brad Arant fd7a9ed860 some smart buffer work. 2025-03-11 07:34:17 -07:00
brad Arant 11f396a749 worked on IMF smartbuffers. 2025-02-21 13:22:57 -08:00
Brad Arant 01180021b4 Work on the IMFHeader and IMFMessage. 2024-11-11 15:58:58 -08:00
Brad Arant a37c4e6829 Updated and working. 2022-01-24 14:03:58 -08:00
Brad Arant d4148b0ab4 Optmizations for IMF objects. 2021-09-23 16:30:33 -07:00
barant ff2c2b7432 All sorts of new crap and adjustments 2021-07-23 11:44:36 -07:00
Brad Arant b6f4bf8a71 Got it compiling and somewhat working, except post. 2020-11-29 13:58:17 -08:00
Brad Arant 41852d019c Sync. 2020-11-16 17:00:28 -08:00
barant 4b6d455689 Sync. 2020-10-27 14:41:06 -07:00
barant 4f95b4591b sync. 2020-08-05 11:57:35 -07:00
barant f4496fc682 Continued refinement of IMF objects. 2020-05-04 10:02:52 -07:00
barant 947eef21e2 Continued work. 2020-03-03 15:46:24 -08:00
barant 08169b1c3d Many additions and changes. 2019-09-13 10:29:36 -07:00
barant 604e196fbb Initial repository load. 2019-07-10 14:19:33 -07:00