Skip to main content

HeaderLookup

Trait HeaderLookup 

Source
pub trait HeaderLookup {
Show 26 methods // Required methods fn header_str(&self, name: &str) -> Option<&str>; fn variable_str(&self, name: &str) -> Option<&str>; // Provided methods fn header(&self, name: EventHeader) -> Option<&str> { ... } fn variable(&self, name: impl VariableName) -> Option<&str> { ... } fn unique_id(&self) -> Option<&str> { ... } fn job_uuid(&self) -> Option<&str> { ... } fn channel_name(&self) -> Option<&str> { ... } fn caller_id_number(&self) -> Option<&str> { ... } fn caller_id_name(&self) -> Option<&str> { ... } fn destination_number(&self) -> Option<&str> { ... } fn callee_id_number(&self) -> Option<&str> { ... } fn callee_id_name(&self) -> Option<&str> { ... } fn hangup_cause(&self) -> Result<Option<HangupCause>, ParseHangupCauseError> { ... } fn event_subclass(&self) -> Option<&str> { ... } fn pl_data(&self) -> Option<&str> { ... } fn sip_event(&self) -> Option<&str> { ... } fn gateway_name(&self) -> Option<&str> { ... } fn channel_state( &self, ) -> Result<Option<ChannelState>, ParseChannelStateError> { ... } fn channel_state_number( &self, ) -> Result<Option<ChannelState>, ParseChannelStateError> { ... } fn call_state(&self) -> Result<Option<CallState>, ParseCallStateError> { ... } fn answer_state(&self) -> Result<Option<AnswerState>, ParseAnswerStateError> { ... } fn call_direction( &self, ) -> Result<Option<CallDirection>, ParseCallDirectionError> { ... } fn priority(&self) -> Result<Option<EslEventPriority>, ParsePriorityError> { ... } fn timetable( &self, prefix: &str, ) -> Result<Option<ChannelTimetable>, ParseTimetableError> { ... } fn caller_timetable( &self, ) -> Result<Option<ChannelTimetable>, ParseTimetableError> { ... } fn other_leg_timetable( &self, ) -> Result<Option<ChannelTimetable>, ParseTimetableError> { ... }
}
Expand description

Trait for looking up ESL headers and channel variables from any key-value store.

Implementors provide two methods – header_str(&str) and variable_str(&str) – and get all typed accessors (channel_state(), call_direction(), timetable(), etc.) as default implementations.

This trait must be in scope to call its methods on EslEvent – including unique_id(), hangup_cause(), and channel_state(). Import it directly or via the prelude:

use freeswitch_esl_tokio::prelude::*;
// or: use freeswitch_esl_tokio::HeaderLookup;
// or: use freeswitch_types::HeaderLookup;

§Example

use std::collections::HashMap;
use freeswitch_types::{HeaderLookup, EventHeader, ChannelVariable};

struct MyStore(HashMap<String, String>);

impl HeaderLookup for MyStore {
    fn header_str(&self, name: &str) -> Option<&str> {
        self.0.get(name).map(|s| s.as_str())
    }
    fn variable_str(&self, name: &str) -> Option<&str> {
        self.0.get(&format!("variable_{}", name)).map(|s| s.as_str())
    }
}

let mut map = HashMap::new();
map.insert("Channel-State".into(), "CS_EXECUTE".into());
map.insert("variable_read_codec".into(), "PCMU".into());
let store = MyStore(map);

// Typed accessor from the trait (returns Result<Option<T>, E>):
assert!(store.channel_state().unwrap().is_some());

// Enum-based lookups:
assert_eq!(store.header(EventHeader::ChannelState), Some("CS_EXECUTE"));
assert_eq!(store.variable(ChannelVariable::ReadCodec), Some("PCMU"));

Required Methods§

Source

fn header_str(&self, name: &str) -> Option<&str>

Look up a header by its raw wire name (e.g. "Unique-ID").

Source

fn variable_str(&self, name: &str) -> Option<&str>

Look up a channel variable by its bare name (e.g. "sip_call_id").

Implementations typically prepend variable_ and delegate to header_str.

Provided Methods§

Source

fn header(&self, name: EventHeader) -> Option<&str>

Look up a header by its EventHeader enum variant.

Source

fn variable(&self, name: impl VariableName) -> Option<&str>

Look up a channel variable by its typed enum variant.

Source

fn unique_id(&self) -> Option<&str>

Unique-ID header, falling back to Caller-Unique-ID.

Source

fn job_uuid(&self) -> Option<&str>

Job-UUID header from bgapi BACKGROUND_JOB events.

Source

fn channel_name(&self) -> Option<&str>

Channel-Name header (e.g. sofia/internal/1000@domain).

Source

fn caller_id_number(&self) -> Option<&str>

Caller-Caller-ID-Number header.

Source

fn caller_id_name(&self) -> Option<&str>

Caller-Caller-ID-Name header.

Source

fn destination_number(&self) -> Option<&str>

Caller-Destination-Number header.

Source

fn callee_id_number(&self) -> Option<&str>

Caller-Callee-ID-Number header.

Source

fn callee_id_name(&self) -> Option<&str>

Caller-Callee-ID-Name header.

Source

fn hangup_cause(&self) -> Result<Option<HangupCause>, ParseHangupCauseError>

Parse the Hangup-Cause header into a HangupCause.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn event_subclass(&self) -> Option<&str>

Event-Subclass header for CUSTOM events (e.g. sofia::register).

Source

fn pl_data(&self) -> Option<&str>

pl_data header – SIP NOTIFY body content from NOTIFY_IN events.

Contains the JSON payload (already percent-decoded by the ESL parser). For NG9-1-1 events this is the inner object without the wrapper key (FreeSWITCH strips it).

Source

fn sip_event(&self) -> Option<&str>

event header – SIP event package name from NOTIFY_IN events.

Examples: emergency-AbandonedCall, emergency-ServiceState.

Source

fn gateway_name(&self) -> Option<&str>

gateway_name header – gateway that received a SIP NOTIFY.

Source

fn channel_state(&self) -> Result<Option<ChannelState>, ParseChannelStateError>

Parse the Channel-State header into a ChannelState.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn channel_state_number( &self, ) -> Result<Option<ChannelState>, ParseChannelStateError>

Parse the Channel-State-Number header into a ChannelState.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn call_state(&self) -> Result<Option<CallState>, ParseCallStateError>

Parse the Channel-Call-State header into a CallState.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn answer_state(&self) -> Result<Option<AnswerState>, ParseAnswerStateError>

Parse the Answer-State header into an AnswerState.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn call_direction( &self, ) -> Result<Option<CallDirection>, ParseCallDirectionError>

Parse the Call-Direction header into a CallDirection.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn priority(&self) -> Result<Option<EslEventPriority>, ParsePriorityError>

Parse the priority header value.

Returns Ok(None) if the header is absent, Err if present but unparseable.

Source

fn timetable( &self, prefix: &str, ) -> Result<Option<ChannelTimetable>, ParseTimetableError>

Extract timetable from timestamp headers with the given prefix.

Returns Ok(None) if no timestamp headers with this prefix are present. Returns Err if a header is present but contains an invalid value.

Source

fn caller_timetable( &self, ) -> Result<Option<ChannelTimetable>, ParseTimetableError>

Caller-leg channel timetable (Caller-*-Time headers).

Source

fn other_leg_timetable( &self, ) -> Result<Option<ChannelTimetable>, ParseTimetableError>

Other-leg channel timetable (Other-Leg-*-Time headers).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl HeaderLookup for HashMap<String, String>

Source§

fn header_str(&self, name: &str) -> Option<&str>

Source§

fn variable_str(&self, name: &str) -> Option<&str>

Source§

impl HeaderLookup for IndexMap<String, String>

Available on crate feature esl only.
Source§

fn header_str(&self, name: &str) -> Option<&str>

Source§

fn variable_str(&self, name: &str) -> Option<&str>

Implementors§