SIP message parser. Port of NkSIP's nksip_parse_sipmsg and nksip_parse.
parse/2 frames the message using Content-Length and parses it into a
Caracola.Message:
- On stream transports (
:tcp,:tls)Content-Lengthis mandatory and:partialis returned while the message is incomplete. - On message transports (
:udp,:sctp,:ws,:wss) a missingContent-Lengthmeans that the body is the rest of the packet. - Any bytes after the message are returned as
rest.
Known headers are validated in the same order as NkSIP, so the reason of a
400 Invalid <header> response is the same.
Summary
Types
The result of parsing: a message and the rest of the data, :partial if more data is needed, or an error.
Functions
Parses a SIP message received over transport.
Same as parse/2 but raises Caracola.ParseError on errors.
Types
@type result() :: {:ok, Caracola.Message.t(), rest :: binary()} | :partial | {:error, Caracola.ParseError.t()}
The result of parsing: a message and the rest of the data, :partial if more data is needed, or an error.
Functions
@spec parse(binary(), Caracola.Via.transport()) :: result()
Parses a SIP message received over transport.
@spec parse!(binary(), Caracola.Via.transport()) :: {Caracola.Message.t(), binary()} | :partial
Same as parse/2 but raises Caracola.ParseError on errors.