#[non_exhaustive]pub struct SipHeaderAddr { /* private fields */ }Expand description
Parsed SIP name-addr (RFC 3261 §25.1) with header-level parameters.
The name-addr production from RFC 3261 §25.1 combines an optional
display name with a URI in angle brackets:
name-addr = [ display-name ] LAQUOT addr-spec RAQUOT
display-name = *(token LWS) / quoted-stringIn SIP headers (From, To, Contact, P-Asserted-Identity,
Refer-To), the name-addr is followed by header-level parameters
(RFC 3261 §20):
from-spec = ( name-addr / addr-spec ) *( SEMI from-param )
from-param = tag-param / generic-paramThis type handles the full production including those trailing
parameters (;tag=, ;expires=, ;serviceurn=, etc.).
Unlike sip_uri::NameAddr (which only handles the name-addr portion),
this type also parses header-level parameters after > and can
round-trip real SIP header values.
use sip_header::SipHeaderAddr;
let addr: SipHeaderAddr = r#""Alice" <sip:alice@example.com>;tag=abc123"#.parse().unwrap();
assert_eq!(addr.display_name(), Some("Alice"));
assert_eq!(addr.tag(), Some("abc123"));Display always emits angle brackets around the URI,
even for bare addr-spec input. This is the canonical form required by
RFC 3261 when header-level parameters are present.
Implementations§
Source§impl SipHeaderAddr
impl SipHeaderAddr
Sourcepub fn new(uri: Uri) -> Self
pub fn new(uri: Uri) -> Self
Create a new SipHeaderAddr with the given URI and no display name or params.
Sourcepub fn with_display_name(self, name: impl Into<String>) -> Self
pub fn with_display_name(self, name: impl Into<String>) -> Self
Set the display name.
Sourcepub fn with_param(
self,
key: impl Into<String>,
value: Option<impl Into<String>>,
) -> Self
pub fn with_param( self, key: impl Into<String>, value: Option<impl Into<String>>, ) -> Self
Add a header-level parameter. The key is lowercased on insertion.
Sourcepub fn display_name(&self) -> Option<&str>
pub fn display_name(&self) -> Option<&str>
The display name, if present.
Sourcepub fn sip_uri(&self) -> Option<&SipUri>
pub fn sip_uri(&self) -> Option<&SipUri>
If the URI is a SIP/SIPS URI, return a reference to it.
Sourcepub fn params(&self) -> impl Iterator<Item = (&str, Option<&str>)>
pub fn params(&self) -> impl Iterator<Item = (&str, Option<&str>)>
Iterator over header-level parameters as (key, raw_value) pairs.
Keys are lowercased; values retain their original percent-encoding.
Sourcepub fn param(
&self,
name: &str,
) -> Option<Result<Option<Cow<'_, str>>, Utf8Error>>
pub fn param( &self, name: &str, ) -> Option<Result<Option<Cow<'_, str>>, Utf8Error>>
Look up a header-level parameter by name (case-insensitive).
Values are percent-decoded and validated as UTF-8. Returns Err if
the percent-decoded octets are not valid UTF-8. For non-UTF-8 values
or raw wire access, use param_raw().
Returns None if the param is not present, Some(Ok(None)) for
flag params (no value), Some(Ok(Some(decoded))) for valued params.
Sourcepub fn param_raw(&self, name: &str) -> Option<Option<&str>>
pub fn param_raw(&self, name: &str) -> Option<Option<&str>>
Look up a raw percent-encoded parameter value (case-insensitive).
Returns the raw value without percent-decoding. Use this when round-trip fidelity matters or the value may not be valid UTF-8.
Sourcepub fn parse_list(
raw: &str,
) -> Result<Vec<SipHeaderAddr>, ParseSipHeaderAddrError>
pub fn parse_list( raw: &str, ) -> Result<Vec<SipHeaderAddr>, ParseSipHeaderAddrError>
Parse a comma-separated list of name-addr / addr-spec values.
Splits on commas at bracket depth zero (via split_comma_entries),
then parses each entry as a SipHeaderAddr. Returns an empty Vec
for empty input. Fails on the first unparseable entry.
Trait Implementations§
Source§impl Clone for SipHeaderAddr
impl Clone for SipHeaderAddr
Source§fn clone(&self) -> SipHeaderAddr
fn clone(&self) -> SipHeaderAddr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more