Rebus.BusAddress (rebus v0.3.0)
View SourceParses D-Bus address lists without opening a connection.
parse/1 accepts a bounded, semicolon-separated list of
transport:key=value entries. It percent-decodes values, but never converts
input into atoms or returns input in an error. The supported transports are
unix (path and abstract) and tcp (host, port, and optional
family). A valid guid is retained as the expected server identity while
being ignored for socket selection. Other syntactically valid, unrecognised
parameters are deliberately discarded: they may be meaningful to a newer
implementation, but do not change a socket address Rebus supports.
A syntactically valid unsupported transport is represented by :unsupported.
Malformed input returns
{:error, {:invalid_bus_address, reason}}, where reason is a fixed atom;
no supplied address data is retained in that result.
Summary
Functions
Parses a D-Bus address list without doing DNS or socket I/O.
Types
@type candidate() :: {:local, binary(), expected_guid()} | {:tcp, binary(), :inet.port_number(), socket_family(), expected_guid()} | :unsupported
@type error_reason() ::
:not_binary
| :too_long
| :too_many_addresses
| :empty_entry
| :invalid_transport
| :invalid_entry
| :too_many_parameters
| :invalid_key
| :duplicate_key
| :invalid_escape
| :nul_byte
| :ambiguous_unix_address
| :missing_path
| :missing_host
| :missing_port
| :invalid_port
| :invalid_family
| :invalid_guid
@type expected_guid() :: binary() | nil
@type socket_family() :: :inet | :inet6 | :unspec
Functions
@spec parse(term()) :: {:ok, [candidate()]} | {:error, {:invalid_bus_address, error_reason()}}
Parses a D-Bus address list without doing DNS or socket I/O.
The list is bounded to 4096 bytes, 16
entries, 16 parameters per entry, and 1024
source bytes per value. Values accept every literal non-NUL, non-percent byte
that does not act as an address separator; percent escapes remain exact, and
a decoded NUL is rejected. A single trailing semicolon is accepted, as
libdbus does; leading, doubled, and otherwise empty entries are rejected. An
abstract socket is encoded with one leading NUL added by the abstract
transport itself.
Examples
iex> Rebus.BusAddress.parse("unix:path=/run/dbus/system_bus_socket")
{:ok, [{:local, "/run/dbus/system_bus_socket", nil}]}
iex> Rebus.BusAddress.parse("tcp:host=127.0.0.1,port=1234,family=ipv4")
{:ok, [{:tcp, "127.0.0.1", 1234, :inet, nil}]}