Documentation
¶
Overview ¶
Package sip decodes SIP messages per RFC 3261. SIP (Session Initiation Protocol) is the dominant VoIP / video / IM signaling protocol on the internet — every PBX / softphone / SBC (Session Border Controller) / WebRTC gateway / unified-communications platform speaks it on UDP/5060 + TCP/5060 + TLS/5061 + WebSocket.
Wrap-vs-native judgement ¶
Native. SIP is a plain-text request/response protocol modelled on HTTP/1.1. The wire format is a start line (request or status) + header field list + blank line + optional body. Headers can use compact forms (m for Contact, v for Via, etc. per RFC 3261 §7.3.3). The optional body is typically SDP (RFC 4566) when carrying media negotiation. Pasting a message from Wireshark "Follow Stream" / tshark sip.* extraction / a captured SIP trace file / a PBX log line is enough — no SIP stack, no DNS lookup, no live network attach.
What this package covers ¶
- **Start line dispatch**: request (METHOD URI VERSION) vs response (VERSION CODE REASON), distinguished by whether the first token starts with "SIP/" (response) or any other text (request).
- **Request methods** (RFC 3261 + 3262 + 3265 + 3428 + 3515 + 3903): INVITE, ACK, BYE, CANCEL, OPTIONS, REGISTER, PRACK, SUBSCRIBE, NOTIFY, PUBLISH, INFO, REFER, MESSAGE, UPDATE.
- **Response status-code lookup** (~40 entries covering all six classes):
- 1xx Provisional: 100 Trying, 180 Ringing, 181 Call Is Being Forwarded, 182 Queued, 183 Session Progress, 199 Early Dialog Terminated.
- 2xx Success: 200 OK, 202 Accepted, 204 No Notification.
- 3xx Redirection: 300 Multiple Choices, 301 Moved Permanently, 302 Moved Temporarily, 305 Use Proxy, 380 Alternative Service.
- 4xx Client error: 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 405 Method Not Allowed, 406 Not Acceptable, 407 Proxy Authentication Required, 408 Request Timeout, 409 Conflict, 410 Gone, 413 Request Entity Too Large, 414 Request-URI Too Long, 415 Unsupported Media Type, 420 Bad Extension, 422 Session Interval Too Small, 423 Interval Too Brief, 480 Temporarily Unavailable, 481 Call/Transaction Does Not Exist, 482 Loop Detected, 483 Too Many Hops, 484 Address Incomplete, 485 Ambiguous, 486 Busy Here, 487 Request Terminated, 488 Not Acceptable Here, 491 Request Pending, 493 Undecipherable.
- 5xx Server error: 500 Server Internal Error, 501 Not Implemented, 502 Bad Gateway, 503 Service Unavailable, 504 Server Time-out, 505 Version Not Supported, 513 Message Too Large.
- 6xx Global failure: 600 Busy Everywhere, 603 Decline, 604 Does Not Exist Anywhere, 606 Not Acceptable.
- **Header field parsing**: case-insensitive name match
- compact-form expansion (RFC 3261 §7.3.3): m→Contact, v→Via, l→Content-Length, t→To, f→From, i→Call-ID, e→Content-Encoding, k→Supported, c→Content-Type, s→Subject. Multi-value headers preserved as ordered lists.
- **Key envelope headers surfaced**: Via (route trace), From, To, Call-ID, CSeq (sequence number + method), Contact, Content-Type, Content-Length, Max-Forwards, User-Agent / Server.
- **CSeq parsing**: sequence number + method broken out (the only header with a fixed two-token grammar).
- **Body decode**: when Content-Type is application/sdp, the body is walked as SDP (RFC 4566) with line-by-line type-name lookup (v=version, o=origin, s=session-name, i=session-info, u=URI, e=email, p=phone, c=connection- info, b=bandwidth, t=timing, r=repeat, z=time-zones, k=encryption, a=attributes, m=media-description) — for media (m=) lines, the protocol + port + RTP-payload- types are surfaced. For other Content-Types, the body is exposed as raw text.
What this package does NOT cover (deliberately out of scope) ¶
- Full SDP attribute (a=) semantic decode — `rtpmap`, `fmtp`, `crypto`, `setup`, `fingerprint`, `ice-ufrag`, `ice-pwd`, `candidate` are surfaced as raw text; full ICE/DTLS-SRTP attribute parsing is a separate ~300 LoC effort.
- Authorization / WWW-Authenticate digest credential parsing — the header value is surfaced but the comma-separated key=value tokens aren't broken out.
- SIP message body parsing for non-SDP content types (multipart/mixed, application/dialog-info+xml, application/pidf+xml, etc.) — body is surfaced as raw text.
- SIP-TLS transport details (the inner message decodes identically once decrypted).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
Header is one header field. Multi-value headers (Via, Contact, Route) preserve their original order.
type Message ¶
type Message struct {
IsRequest bool `json:"is_request"`
IsResponse bool `json:"is_response"`
Method string `json:"method,omitempty"`
RequestURI string `json:"request_uri,omitempty"`
Version string `json:"version"`
StatusCode int `json:"status_code,omitempty"`
StatusReason string `json:"status_reason,omitempty"`
StatusName string `json:"status_name,omitempty"`
Headers []*Header `json:"headers"`
CallID string `json:"call_id,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Via []string `json:"via,omitempty"`
CSeq *CSeq `json:"cseq,omitempty"`
Contact []string `json:"contact,omitempty"`
ContentType string `json:"content_type,omitempty"`
ContentLength int `json:"content_length,omitempty"`
MaxForwards int `json:"max_forwards,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Server string `json:"server,omitempty"`
BodyRaw string `json:"body_raw,omitempty"`
SDP *SDP `json:"sdp,omitempty"`
}
Message is the decoded SIP message view.
type SDP ¶
type SDP struct {
Version string `json:"version,omitempty"`
Origin string `json:"origin,omitempty"`
SessionName string `json:"session_name,omitempty"`
Connection string `json:"connection,omitempty"`
Timing string `json:"timing,omitempty"`
Media []*SDPMedia `json:"media,omitempty"`
OtherLines []string `json:"other_lines,omitempty"`
}
SDP is the decoded session description (RFC 4566).
type SDPMedia ¶
type SDPMedia struct {
Type string `json:"type"` // audio / video / application / etc.
Port int `json:"port"`
Protocol string `json:"protocol"` // RTP/AVP, RTP/SAVP, UDP, etc.
PayloadTypes []string `json:"payload_types"`
Attributes []string `json:"attributes,omitempty"`
}
SDPMedia is one m= line + its attributes.