dialog

package
v1.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package dialog tracks minimal SIP dialog identifiers for UAS-centric call legs.

A dialog is created by an INVITE and confirmed by ACK (RFC 3261 §12). This package stores the fields needed to match in-dialog requests and ACKs without parsing SDP:

  • Call-ID — dialog identifier (same for the whole call leg)
  • InviteBranch — top Via branch of the creating INVITE (transaction layer key)
  • CSeqInvite — INVITE sequence number (ACK reuses it with method ACK)
  • RemoteTag — typically ;tag= from the INVITE From (caller)
  • LocalTag — ;tag= added by the UAS on To in 1xx/2xx

Example INVITE establishing a dialog:

INVITE sip:bob@example.com SIP/2.0
Via: SIP/2.0/UDP 192.0.2.1:5060;branch=z9hG4bK776asdhds
From: Alice <sip:alice@example.com>;tag=1928301774
To: Bob <sip:bob@example.com>
Call-ID: a84b4c76e66710@192.0.2.1
CSeq: 314159 INVITE

After 200 OK, To contains the UAS tag:

To: Bob <sip:bob@example.com>;tag=a6c85cf

Matching ACK:

ACK sip:bob@example.com SIP/2.0
Via: SIP/2.0/UDP 192.0.2.1:5060;branch=z9hG4bK776asdhds
From: Alice <sip:alice@example.com>;tag=1928301774
To: Bob <sip:bob@example.com>;tag=a6c85cf
Call-ID: a84b4c76e66710@192.0.2.1
CSeq: 314159 ACK

Usage

d, err := dialog.NewUASFromINVITE(invite)
d.SetLocalTagFromToHeader(resp.GetHeader(stack.HeaderTo))
d.Confirm()
if d.MatchACK(ack) { ... }

Registry stores one Dialog per Call-ID for simple B2BUA/UAS apps.

Media and SDP negotiation live in protocol/sipmedia/session, not here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendTagAfterNameAddr

func AppendTagAfterNameAddr(header, tag string) string

AppendTagAfterNameAddr inserts ;tag=tag immediately after the closing '>' of a name-addr, or appends ;tag=tag when no angle brackets are present. If a tag already exists, header is unchanged.

func TagFromHeader

func TagFromHeader(header string) string

TagFromHeader extracts the SIP tag parameter from a From or To header value.

Types

type Dialog

type Dialog struct {
	CallID       string
	InviteBranch string // top Via branch of the INVITE; matches transaction layer key
	CSeqInvite   int    // INVITE CSeq number (ACK uses same number with method ACK)

	// RemoteTag is typically the peer tag from the INVITE From (caller).
	RemoteTag string
	// LocalTag is the UAS tag added to To in 1xx/2xx responses.
	LocalTag string
	// contains filtered or unexported fields
}

Dialog holds minimal identifiers for one SIP dialog (UAS-centric helpers).

func NewUASFromINVITE

func NewUASFromINVITE(inv *stack.Message) (*Dialog, error)

NewUASFromINVITE builds dialog state from an inbound INVITE (early). Parses Call-ID, branch, INVITE CSeq, remote From tag.

func (*Dialog) Confirm

func (d *Dialog) Confirm()

Confirm marks the dialog confirmed (e.g. after stable 2xx/ACK path).

func (*Dialog) GetLocalTag

func (d *Dialog) GetLocalTag() string

GetLocalTag returns the UAS tag for this dialog (empty before 2xx To is set).

func (*Dialog) GetRemoteTag

func (d *Dialog) GetRemoteTag() string

GetRemoteTag returns the peer tag parsed from the INVITE From.

func (*Dialog) InviteCSeqNum

func (d *Dialog) InviteCSeqNum() int

InviteCSeqNum returns the CSeq number of the INVITE that created this dialog (ACK uses the same number).

func (*Dialog) InviteTransactionKey

func (d *Dialog) InviteTransactionKey() string

InviteTransactionKey returns the same key used by protocol/sip/transaction INVITE maps.

func (*Dialog) MatchACK

func (d *Dialog) MatchACK(ack *stack.Message) bool

MatchACK reports whether ack belongs to this dialog's INVITE (same Call-ID, CSeq number, ACK method, tags when present).

func (*Dialog) SetLocalTag

func (d *Dialog) SetLocalTag(tag string)

SetLocalTag records the UAS tag (usually parsed from the To header you generated on 1xx/2xx).

func (*Dialog) SetLocalTagFromToHeader

func (d *Dialog) SetLocalTagFromToHeader(toHeader string)

SetLocalTagFromToHeader extracts ;tag= from a To header value (e.g. your generated 200 OK To).

func (*Dialog) State

func (d *Dialog) State() State

State returns the current dialog state.

func (*Dialog) Terminate

func (d *Dialog) Terminate()

Terminate marks the dialog terminated.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores dialogs keyed by Call-ID (single dialog per Call-ID for this minimal registry).

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Delete

func (r *Registry) Delete(callID string)

Delete removes a dialog by Call-ID.

func (*Registry) Get

func (r *Registry) Get(callID string) *Dialog

Get returns the dialog for Call-ID or nil.

func (*Registry) Put

func (r *Registry) Put(d *Dialog) error

Put registers d under its Call-ID (must be non-empty).

type State

type State int

State is the dialog lifecycle for a UAS leg (inbound INVITE).

const (
	StateNone State = iota
	StateEarly
	StateConfirmed
	StateTerminated
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL