Parrot.Sip.Headers.Contact (Parrot Platform v0.0.1-alpha.2)

Module for working with SIP Contact headers as defined in RFC 3261 Section 20.10.

The Contact header provides a URI where the user can be reached for subsequent requests. It plays a critical role in dialog establishment, request routing, and registrations. Its meaning depends on the type of request or response it appears in:

  • In REGISTER requests: Specifies where the user can be reached
  • In INVITE requests: Indicates where the caller can be reached
  • In 2xx responses to INVITE: Specifies where the callee can be reached
  • In 3xx responses: Provides alternative locations to retry the request

The Contact header can contain parameters:

  • expires: Indicates how long the URI is valid (seconds)
  • q-value: Indicates preference among multiple contacts
  • methods: Specifies which methods the contact supports
    • (wildcard): Special form used only in REGISTER requests for removal

References:

  • RFC 3261 Section 8.1.1.8: Contact
  • RFC 3261 Section 10: Registrations
  • RFC 3261 Section 12.1.1: UAC Behavior
  • RFC 3261 Section 20.10: Contact Header Field

Summary

Functions

Gets the expires parameter from a Contact header.

Converts a Contact header to a string representation.

Gets a parameter from a Contact header.

Creates a new Contact header.

Parses a Contact header string into a Contact struct.

Gets the q-value parameter from a Contact header.

Creates a new wildcard Contact header.

Sets the expires parameter in a Contact header.

Adds or updates a parameter in a Contact header.

Sets the q-value parameter in a Contact header.

Types

t()

@type t() :: %Parrot.Sip.Headers.Contact{
  display_name: String.t() | nil,
  parameters: map(),
  uri: String.t() | Parrot.Sip.Uri.t() | nil,
  wildcard: boolean()
}

Functions

expires(contact)

@spec expires(t()) :: integer() | nil

Gets the expires parameter from a Contact header.

format(contact)

@spec format(t()) :: String.t()

Converts a Contact header to a string representation.

get_parameter(contact, name)

@spec get_parameter(t(), String.t()) :: String.t() | nil

Gets a parameter from a Contact header.

new(uri, display_name \\ nil, parameters \\ %{})

@spec new(String.t(), String.t() | nil, map()) :: t()

Creates a new Contact header.

parse(string)

@spec parse(String.t()) :: t()

Parses a Contact header string into a Contact struct.

Examples

iex> Parrot.Sip.Headers.Contact.parse("Alice <sip:alice@pc33.atlanta.com>;expires=3600")
%Parrot.Sip.Headers.Contact{display_name: "Alice", uri: %Parrot.Sip.Uri{scheme: "sip", user: "alice", host: "pc33.atlanta.com"}, parameters: %{"expires" => "3600"}, wildcard: false}

iex> Parrot.Sip.Headers.Contact.parse("*")
%Parrot.Sip.Headers.Contact{display_name: nil, uri: nil, parameters: %{}, wildcard: true}

q(contact)

@spec q(t()) :: float() | nil

Gets the q-value parameter from a Contact header.

wildcard()

@spec wildcard() :: t()

Creates a new wildcard Contact header.

with_expires(contact, expires)

@spec with_expires(t(), integer()) :: t()

Sets the expires parameter in a Contact header.

with_parameter(contact, name, value)

@spec with_parameter(t(), String.t(), String.t()) :: t()

Adds or updates a parameter in a Contact header.

with_q(contact, q)

@spec with_q(t(), float()) :: t()

Sets the q-value parameter in a Contact header.