Skip to main content

Module wire

Module wire 

Source
Expand description

DICT (RFC 2229) wire format: command parsing and response rendering.

Everything here is a pure function of its arguments, so the session loop, the action executor and the tests all share one definition of what a DICT line looks like. The model never writes a byte of framing: it supplies words, database names and free text, and this module decides the status lines, the quoting, the dot-stuffing and the terminator. A model that writes a definition whose line happens to be . produces a line reading .. on the wire, and the client’s un-stuffing turns it back into . — not a premature end of the text.

Structs§

Definition
One definition, as the model supplies it.

Enums§

ArgError
Why a command line could not be split into parameters.

Constants§

ERROR_CODES
The 5xx codes send_dict_error may send, each with RFC 2229’s own text as its default.
MAX_LINE_BYTES
The longest command line a peer may send, including the trailing CRLF.
MAX_TEXT_LINE_CONTENT
The longest text line this server writes, before dot-stuffing and CRLF.
MIME_HEADER
The header a MIME-mode text block is prefaced with (RFC 2229 §3.10.1, OPTION MIME).
TEXT_CODES
The three informational text responses send_dict_text renders, with their status text.
TEXT_FOLLOWS_CODES
Status codes whose response is followed by a dot-terminated text block.

Functions§

apply_mime
Insert MIME_HEADER after every status line that opens a text block.
atom
Render a database or strategy name: bare when it is a plain atom (which every real name is — wn, gcide, prefix), quoted otherwise so a name with a space in it cannot split one listing line into two columns.
leading_code
The numeric code a rendered response begins with.
quoted
Render a string as a DICT double-quoted string: control characters become spaces (a CR or LF would end the status line and forge the next one), and \ and " are escaped.
render_databases
render_definitions
150 + one 151 block per definition + 250, or 552 no match when there are none.
render_error
A single 5xx status line. None for a code outside ERROR_CODES.
render_listing
A name "description" listing (110 databases or 111 strategies) + 250, or the listing’s own empty-set code (554 / 555).
render_matches
152 + one database "word" line per match + 250, or 552 no match.
render_strategies
render_text
112 / 113 / 114 + a text block + 250. None for any other code.
split_args
Split a command line into parameters per RFC 2229 §2.2.
stuff
Dot-stuff one text line (RFC 2229 §2.4.1): a line that begins with . gets a second one, so the only line that reads as . alone is the terminator this module writes.
text_block
A status line followed by a dot-terminated text block.
text_lines
The lines of a model-supplied text body, ready for a text block: line endings normalised, control characters other than tab removed, long lines wrapped, trailing blank lines dropped. Not yet dot-stuffed — text_block does that, once, for every line it writes.