4 Commits
Author SHA1 Message Date
Matt Diephouse 7d0f2cf799 Mark final set of types as Sendable (#771) 2024-09-18 15:06:30 +02:00
David Evans 69f15a10ba Convert line length limit to 8192 (#666)
Resolves #663

Convert the default limits from 1000 to 8192 octets, as per RFC 7162.
2021-12-23 13:36:54 +00:00
David Evans 1615507941 Implement FramingResult (#622)
This introduces FramingResult, which signals either a "complete" frame, "incomplete", or "invalid".

If a frame is incomplete then the minimum number of required bytes to make a complete frame are sent.

if a frame is invalid or complete then you are provided with the bytes in that frame.

Invalid frames are forwarded onto the user via user events.

It doesn't have many bells and whistles yet, but it handles a lot of use cases we'll see in the wild, and you'll probably still find it useful

Given the command A1 LOG it will delivered .incompleteFrame(2) to signal that this frame is incomplete, and that we need at least 2 more bytes (in this case the CR and LF) to complete the frame (this is because it doesn't have the ability to understand the login command fully as it's only used to build frames).

Given the command A1 LOGIN {3}\r\na it will deliver 2 frames:

.complete("A1 LOGIN {3}\r\n
.complete("a") this is a "complete" frame because we're streaming a literal, so need to forward all bytes as soon as possible
Finally a case of invalid, A1 LOGIN {a will deliver 1 frame containing the data, including the byte where we detected the issue: .invalid("A1 LOGIN {a")
2021-12-09 11:09:09 +00:00
David EvansandCory Benfield 275a907a86 Implement the beginnings of a framing parser (#614)
* Boilerplate

* Add extremely simple tests cases

* Basic literal support

* Add literal+, literal-, and binary support

* Fix backtracking

* Start some integration tests

* A few type renames

* Make the framer throwing

* Soundness

* Address some of Cory's comments

* More graceful handling or CRs and LFs

* Apple Cory suggestions part 2

* Swallow LF

* Make it all work

* Refactor

* Define LineFeedStrategy enum

* Refactor integer parsing and add frame status

* Digit constants

* Refactor adjusting frame length

* Defend against infinite size

* Fix literal bugs

* Soundness

* Add some docs

* Update Sources/NIOIMAP/Client/FramingParser.swift

Co-authored-by: Cory Benfield <lukasa@apple.com>

* Prefer () over break

* Use UInt64 where appropriate

* Implement a stepback function

* Fix FrameSatus typo

* Don't allocate 2 buffers

* Rename LiteralSubstate to LiteralHeaderState

* Use Float64

* Remove frame debugging function

* Fix empty frame logic

* Discard empty bytes

* Fix handing optional LF in a literal

* Soundness

* Remove random Darwin import

* Cory nits

* Discard when we've read over half the buffer

* Read at least 1KB before cleaning

* Soundness

* Fix precondition

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-09-15 16:38:03 +01:00