Parrot.Sip.DialogId (Parrot Platform v0.0.1-alpha.2)
Module for working with SIP dialog identifiers as defined in RFC 3261.
A dialog ID uniquely identifies a dialog between two user agents. As per RFC 3261 Section 12, a dialog is identified by:
- Call-ID
- Local tag (From tag for the UAC, To tag for the UAS)
- Remote tag (To tag for the UAC, From tag for the UAS)
This module provides functions for creating and handling dialog IDs, which are essential for tracking and managing SIP dialogs.
References:
- RFC 3261 Section 12: Dialogs
- RFC 3261 Section 12.1.1: Dialog ID
- RFC 3261 Section 19.3: Dialog ID Components
Summary
Functions
Creates a dialog ID from a SIP message.
Checks if a dialog ID is complete (has both local and remote tags).
Compares two dialog IDs to determine if they match. Two dialog IDs match if they have the same call-id and tags.
Creates a dialog ID with explicit components.
Creates a peer dialog ID by swapping local and remote tags. This is useful for matching dialog IDs from different endpoints.
Converts a dialog ID to a string representation.
Updates a dialog ID with a remote tag, typically used when receiving a response that establishes a dialog.
Types
Functions
@spec from_message(Parrot.Sip.Message.t()) :: t()
Creates a dialog ID from a SIP message.
For requests, the dialog ID is created from the From tag, To tag (if present), and Call-ID. For responses, the dialog ID is created from the To tag, From tag, and Call-ID.
The direction is determined by the message type. For requests, the direction is :uac (User Agent Client). For responses, the direction is :uas (User Agent Server).
Examples
iex> request = %Parrot.Sip.Message{type: :request, direction: :incoming, headers: %{
...> "from" => %Parrot.Sip.Headers.From{parameters: %{"tag" => "123"}},
...> "to" => %Parrot.Sip.Headers.To{parameters: %{}},
...> "call-id" => "abc@example.com"
...> }}
iex> Parrot.Sip.DialogId.from_message(request)
%Parrot.Sip.DialogId{
call_id: "abc@example.com",
local_tag: "123",
remote_tag: nil,
direction: :uas
}
Checks if a dialog ID is complete (has both local and remote tags).
Examples
iex> dialog_id = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456"}
iex> Parrot.Sip.DialogId.is_complete?(dialog_id)
true
iex> dialog_id = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: nil}
iex> Parrot.Sip.DialogId.is_complete?(dialog_id)
false
Compares two dialog IDs to determine if they match. Two dialog IDs match if they have the same call-id and tags.
Examples
iex> dialog_id1 = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456"}
iex> dialog_id2 = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456"}
iex> Parrot.Sip.DialogId.match?(dialog_id1, dialog_id2)
true
iex> dialog_id1 = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456", direction: :uac}
iex> dialog_id2 = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "456", remote_tag: "123", direction: :uas}
iex> Parrot.Sip.DialogId.match?(dialog_id1, dialog_id2)
true
Creates a dialog ID with explicit components.
Examples
iex> Parrot.Sip.DialogId.new("abc@example.com", "123", "456", :uac)
%Parrot.Sip.DialogId{
call_id: "abc@example.com",
local_tag: "123",
remote_tag: "456",
direction: :uac
}
Creates a peer dialog ID by swapping local and remote tags. This is useful for matching dialog IDs from different endpoints.
Examples
iex> dialog_id = %Parrot.Sip.DialogId{
...> call_id: "abc@example.com",
...> local_tag: "123",
...> remote_tag: "456",
...> direction: :uac
...> }
iex> Parrot.Sip.DialogId.peer_dialog_id(dialog_id)
%Parrot.Sip.DialogId{
call_id: "abc@example.com",
local_tag: "456",
remote_tag: "123",
direction: :uas
}
Converts a dialog ID to a string representation.
Examples
iex> dialog_id = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456", direction: :uac}
iex> Parrot.Sip.DialogId.to_string(dialog_id)
"abc;local=123;remote=456;uac"
Updates a dialog ID with a remote tag, typically used when receiving a response that establishes a dialog.
Examples
iex> dialog_id = %Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: nil}
iex> Parrot.Sip.DialogId.with_remote_tag(dialog_id, "456")
%Parrot.Sip.DialogId{call_id: "abc", local_tag: "123", remote_tag: "456"}