Skip to main content

Crate sip_uri

Crate sip_uri 

Source
Expand description

Zero-dependency SIP/SIPS, tel:, and URN parser.

Implements RFC 3261 §19/§25 (SIP-URI, SIPS-URI), RFC 3966 (tel-URI), and RFC 8141 (URN) with hand-written parsing and per-component percent-encoding.

§Examples

use sip_uri::{SipUri, TelUri, UrnUri, Uri};

// Parse a SIP URI
let uri: SipUri = "sip:alice@example.com;transport=tcp".parse().unwrap();
assert_eq!(uri.user(), Some("alice"));
assert_eq!(uri.param("transport"), Some(&Some("tcp".to_string())));

// Parse a tel: URI
let tel: TelUri = "tel:+15551234567;cpc=emergency".parse().unwrap();
assert_eq!(tel.number(), "+15551234567");
assert!(tel.is_global());

// Parse a URN (e.g. NG911 service identifier)
let urn: UrnUri = "urn:service:sos".parse().unwrap();
assert_eq!(urn.nid(), "service");
assert_eq!(urn.nss(), "sos");

// Dispatch on URI type
let uri: Uri = "urn:service:sos".parse().unwrap();
match uri {
    Uri::Sip(sip) => println!("SIP: {sip}"),
    Uri::Tel(tel) => println!("Tel: {tel}"),
    Uri::Urn(urn) => println!("URN: {urn}"),
    Uri::Other(raw) => println!("other: {raw}"),
    _ => {}
}

Structs§

NameAddrDeprecated
A SIP name-addr: optional display name with a URI.
ParseNameAddrError
Error returned when parsing a NameAddr fails.
ParseSipUriError
Error returned when parsing a SIP or SIPS URI fails.
ParseTelUriError
Error returned when parsing a tel: URI fails.
ParseUriError
Error returned when parsing a Uri fails.
ParseUrnError
Error returned when parsing a URN fails.
SipUri
SIP or SIPS URI per RFC 3261 §19.
TelUri
tel: URI per RFC 3966.
UrnUri
URN (Uniform Resource Name) per RFC 8141.

Enums§

Host
Host component of a SIP URI.
Scheme
SIP URI scheme.
Uri
A parsed URI: SIP/SIPS, tel, URN, or an opaque URI with an unrecognized scheme.