Sovite.Core.Postfix.MasterCf (sovite v0.6.0)

Copy Markdown View Source

Reads Postfix's master.cf, for Sovite.Core.Postfix.Migration.

Each logical line (see Sovite.Core.Postfix.MainCf.logical_lines/1) is a service: name, type, private, unpriv, chroot, wakeup, maxproc, and the command with its arguments. Arguments are separated by whitespace; { ... } groups one argument that contains whitespace. -o name=value and -o { name = value } override a main.cf parameter for the service.

Summary

Functions

The name=value attributes of a pipe or spawn service, with "argv" as the list of the command and its arguments.

The address and port of an inet service name: smtp, 587, 127.0.0.1:10025, [::1]:25. The host is nil when the service listens on inet_interfaces.

The value of -o name=... on service, or nil. The last one wins.

Parses contents into services, in file order. Malformed lines are skipped.

Splits a line into whitespace-separated tokens, keeping { ... } groups whole.

Types

service()

@type service() :: %{
  name: String.t(),
  type: String.t(),
  private: String.t(),
  unpriv: String.t(),
  chroot: String.t(),
  wakeup: String.t(),
  maxproc: String.t(),
  command: String.t(),
  args: [String.t()],
  options: [{String.t(), String.t()}],
  line: pos_integer()
}

Functions

attributes(args)

@spec attributes([String.t()]) :: %{required(String.t()) => String.t() | [String.t()]}

The name=value attributes of a pipe or spawn service, with "argv" as the list of the command and its arguments.

iex> Sovite.Core.Postfix.MasterCf.attributes(["flags=Rq", "user=nobody", "argv=/bin/cat", "-n"])
%{"flags" => "Rq", "user" => "nobody", "argv" => ["/bin/cat", "-n"]}

inet_address(name)

@spec inet_address(String.t()) ::
  {:ok, String.t() | nil, :inet.port_number()} | :error

The address and port of an inet service name: smtp, 587, 127.0.0.1:10025, [::1]:25. The host is nil when the service listens on inet_interfaces.

iex> Sovite.Core.Postfix.MasterCf.inet_address("127.0.0.1:10025")
{:ok, "127.0.0.1", 10025}
iex> Sovite.Core.Postfix.MasterCf.inet_address("submission")
{:ok, nil, 587}

option(service, name)

@spec option(service(), String.t()) :: String.t() | nil

The value of -o name=... on service, or nil. The last one wins.

parse(contents)

@spec parse(String.t()) :: [service()]

Parses contents into services, in file order. Malformed lines are skipped.

tokens(line)

@spec tokens(String.t()) :: [String.t()]

Splits a line into whitespace-separated tokens, keeping { ... } groups whole.

iex> Sovite.Core.Postfix.MasterCf.tokens("a  -o { x = 1 } b")
["a", "-o", "{ x = 1 }", "b"]