sip-header 0.3.13

SIP header field parsers: Via, Warning, Auth, Accept, Contact, Call-Info, History-Info, Geolocation, Security, and full IANA header catalog
Documentation

sip-header

SIP header field parsers for Rust. Via, Warning, Auth, Accept, Contact, Call-Info, History-Info, Geolocation, Security, and full IANA header catalog.

CI crates.io docs.rs tests SipHeader SipHeaderLookup

Sits between URI parsing (sip-uri) and full SIP stacks, handling the header-level grammar: display names, header parameters, and structured header values.

[dependencies]
sip-header = "0.3"

SipHeaderAddr — RFC 3261 name-addr

Parses [display-name] <URI> ;param=value with header-level parameters (tag, expires, etc.):

use sip_header::SipHeaderAddr;

let addr: SipHeaderAddr = r#""EXAMPLE CO" <sip:+15551234567@198.51.100.1>;tag=abc123"#
    .parse().unwrap();
assert_eq!(addr.display_name(), Some("EXAMPLE CO"));
assert_eq!(addr.tag(), Some("abc123"));
assert_eq!(addr.sip_uri().unwrap().user(), Some("+15551234567"));

UriInfo — Call-Info / Alert-Info / Error-Info

Parses <absoluteURI> *(SEMI generic-param) headers:

use sip_header::UriInfo;

let raw = "<urn:emergency:uid:callid:abc:bcf.example.com>;purpose=emergency-CallId,\
           <https://adr.example.com/info>;purpose=EmergencyCallData.ProviderInfo";
let ci = UriInfo::parse(raw).unwrap();
assert_eq!(ci.len(), 2);
assert_eq!(ci.entries()[0].purpose(), Some("emergency-CallId"));

HistoryInfo — RFC 7044

Parses History-Info routing chains with embedded RFC 3326 Reason headers:

use sip_header::HistoryInfo;

let raw = "<sip:alice@esrp.example.com>;index=1,\
           <sip:sos@psap.example.com>;index=1.1";
let hi = HistoryInfo::parse(raw).unwrap();
assert_eq!(hi.len(), 2);
assert_eq!(hi.entries()[0].index(), Some("1"));

SipHeaderLookup trait

Typed accessors for any key-value store holding SIP headers:

use std::collections::HashMap;
use sip_header::SipHeaderLookup;

let mut headers = HashMap::new();
headers.insert(
    "Call-Info".to_string(),
    "<urn:example:test>;purpose=icon".to_string(),
);
let ci = headers.call_info().unwrap().unwrap();
assert_eq!(ci.entries()[0].purpose(), Some("icon"));

SipHeader enum — full IANA registry

The SipHeader enum covers all registered SIP header field names from the IANA SIP Parameters registry. Use it for typed lookups, or fall back to sip_header_str() for unregistered headers.

Compact header forms (RFC 3261 §7.3.3)

All IANA-registered compact forms are supported:

use sip_header::SipHeader;

assert_eq!(SipHeader::from_compact(b'f'), Some(SipHeader::From));
assert_eq!(SipHeader::From.compact_form(), Some('f'));
assert_eq!(SipHeader::parse_name("v"), Ok(SipHeader::Via));

extract_header() matches both forms transparently — searching for "From" also matches f: lines, and vice versa.

Bulk extraction

extract_all_headers() returns all headers as name-value tuples in wire order, with proper RFC 3261 §7.3.1 folding. Header names are returned verbatim (compact forms are not expanded):

use sip_header::extract_all_headers;

let msg = "INVITE sip:bob@example.com SIP/2.0\r\n\
           Via: SIP/2.0/UDP host\r\n\
           f: Alice <sip:alice@example.com>\r\n\
           \r\n";
let headers = extract_all_headers(msg);
assert_eq!(headers[0].0, "Via");
assert_eq!(headers[1].0, "f");  // not "From"

Modules

Module Description
header_addr RFC 3261 name-addr with header-level parameters
header SipHeader enum, SipHeaderLookup trait
call_id RFC 3261 Call-ID value
message Extract headers and body from raw SIP message text
via RFC 3261 Via header parser
warning RFC 3261 Warning header parser
auth SIP authentication (Authorization, WWW-Authenticate, etc.)
contact RFC 3261 Contact header parser
accept RFC 3261 Accept header parser
accept_encoding RFC 3261 Accept-Encoding header parser
accept_language RFC 3261 Accept-Language header parser
security RFC 3329 Security-Client/Server/Verify
uri_info Call-Info, Alert-Info, Error-Info (URI + params)
history_info RFC 7044 History-Info with RFC 3326 Reason
geolocation RFC 6442 Geolocation header
replaces RFC 3891 Replaces / RFC 3911 Join headers
target_dialog RFC 4538 Target-Dialog header
conference_info RFC 4575 conference event XML (feature: conference-info)

Features

Feature Dependencies Description
message — Raw SIP message extraction (extract_header, extract_body, …); on by default
serde serde Serde derives on the header-name catalog enums
draft — Widely-deployed headers from expired IETF drafts (Diversion, Remote-Party-ID)
conference-info quick-xml, serde RFC 4575 XML parsing

Ecosystem

This crate is part of a Rust SIP/NG9-1-1 ecosystem:

  • sip-uri — RFC 3261/3966/8141 URI parser
  • sip-header — SIP header field parsers (this crate)
  • eido — NENA NG9-1-1 emergency data types
  • freeswitch-types — FreeSWITCH ESL protocol types (re-exports sip-header)

RFC coverage

  • RFC 3261 — Via, Warning, Contact, Accept, Accept-Encoding, Accept-Language, name-addr, Call-Info, core header catalog
  • RFC 2617 — Digest authentication (Authorization, WWW-Authenticate)
  • RFC 3325 — P-Asserted-Identity, P-Preferred-Identity
  • RFC 3326 — Reason header (embedded in History-Info)
  • RFC 3329 — Security mechanism (Security-Client/Server/Verify)
  • RFC 3891 — Replaces header (top-level and URI-header framings)
  • RFC 3911 — Join header
  • RFC 4538 — Target-Dialog header
  • RFC 4575 — Conference event package XML (feature-gated)
  • RFC 6442 — Geolocation header
  • RFC 7044 — History-Info header

Development

cargo fmt --all
cargo clippy --message-format=short
RUSTDOCFLAGS="-D missing_docs -D rustdoc::broken_intra_doc_links" cargo doc --no-deps
cargo test

The pre-commit hook validates the SipHeader enum against the IANA registry (iana-sip-headers.txt).

License

MIT OR Apache-2.0 — see LICENSE-MIT and LICENSE-APACHE.