webrtc_sdp_lex (webrtc v0.1.0)

View Source

Lexical helpers shared by the SDP codec modules.

Character classes follow the ABNF of RFC 8866 §9 (token, byte-string, non-ws-string), RFC 8839 §5.1 (ice-char) and RFC 8851 (rid-id). Every parser here returns {ok, Value} or error and never raises on malformed input.

Summary

Functions

Raise {invalid_sdp, {What, Value}} unless Value is a binary that can sit on a single SDP line. Used on the encode path to prevent line injection.

Encode a non-negative integer.

ice-char string (RFC 8839): ALPHA / DIGIT / "+" / "/".

non-ws-string: one or more VCHAR or bytes 0x80-0xFF.

rid-id (RFC 8851): 1*(alpha-numeric / "-" / "_").

byte-string (any byte except NUL, CR, LF), possibly empty.

token of RFC 8866: one or more token-char.

ASCII lowercase, byte by byte.

Parse a connection or candidate address: IPv4, IPv6 or FQDN (RFC 8866 unicast-address without extn-addr). The presence of a colon selects IPv6 (RFC 8839 §5.1).

Parse 1*DIGIT (at most 20 digits).

Parse non-zero-int-or-real (RFC 8866 §9), as used by ptime, maxptime and framerate. Integers stay integers.

Split at the first occurrence of Sep.

Split on single spaces. Returns error on empty fields, so doubled, leading or trailing spaces are rejected.

Strip leading and trailing spaces and tabs. Works on bytes, so input that is not valid UTF-8 is fine.

Types

address/0

-type address() :: inet:ip_address() | binary().

Functions

check_text(What, V)

-spec check_text(term(), term()) -> ok.

Raise {invalid_sdp, {What, Value}} unless Value is a binary that can sit on a single SDP line. Used on the encode path to prevent line injection.

encode_address(B)

-spec encode_address(address()) -> binary().

encode_number(N)

-spec encode_number(number()) -> binary().

int(N)

-spec int(non_neg_integer()) -> binary().

Encode a non-negative integer.

is_digits(B)

-spec is_digits(binary()) -> boolean().

is_ice_chars(B)

-spec is_ice_chars(binary()) -> boolean().

ice-char string (RFC 8839): ALPHA / DIGIT / "+" / "/".

is_non_ws(B)

-spec is_non_ws(binary()) -> boolean().

non-ws-string: one or more VCHAR or bytes 0x80-0xFF.

is_rid_id(B)

-spec is_rid_id(binary()) -> boolean().

rid-id (RFC 8851): 1*(alpha-numeric / "-" / "_").

is_text(B)

-spec is_text(binary()) -> boolean().

byte-string (any byte except NUL, CR, LF), possibly empty.

is_token(B)

-spec is_token(binary()) -> boolean().

token of RFC 8866: one or more token-char.

lower(B)

-spec lower(binary()) -> binary().

ASCII lowercase, byte by byte.

parse_address(B)

-spec parse_address(binary()) -> {ok, address()} | error.

Parse a connection or candidate address: IPv4, IPv6 or FQDN (RFC 8866 unicast-address without extn-addr). The presence of a colon selects IPv6 (RFC 8839 §5.1).

parse_int(B)

-spec parse_int(binary()) -> {ok, non_neg_integer()} | error.

Parse 1*DIGIT (at most 20 digits).

parse_int(B, Min, Max)

-spec parse_int(binary(), integer(), integer() | infinity) -> {ok, non_neg_integer()} | error.

parse_number(B)

-spec parse_number(binary()) -> {ok, number()} | error.

Parse non-zero-int-or-real (RFC 8866 §9), as used by ptime, maxptime and framerate. Integers stay integers.

split_first(B, Sep)

-spec split_first(binary(), binary()) -> {binary(), binary() | undefined}.

Split at the first occurrence of Sep.

split_sp(B)

-spec split_sp(binary()) -> {ok, [binary(), ...]} | error.

Split on single spaces. Returns error on empty fields, so doubled, leading or trailing spaces are rejected.

trim_sp(B)

-spec trim_sp(binary()) -> binary().

Strip leading and trailing spaces and tabs. Works on bytes, so input that is not valid UTF-8 is fine.