Rebus.BusAddress (rebus v0.4.0)
View SourceParses D-Bus address lists without opening a connection.
parse/1 takes a semicolon-separated list of transport:key=value
entries. The supported transports are unix, with path or abstract,
and tcp, with host, port and an optional family. A guid is kept
as the server identity to expect, and plays no part in choosing the
socket. Other well-formed parameters are ignored: a newer implementation
may give them meaning, but they do not change a socket address Rebus
supports.
Values are percent-decoded, but input is never turned into atoms, and no
input appears in an error. A well-formed entry for an unsupported
transport parses as :unsupported. Malformed input returns
{:error, {:invalid_bus_address, reason}}, where reason is a fixed atom.
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}]}