Skip to main content

freeswitch_types/variables/
mod.rs

1//! Channel variable types: format parsers (`ARRAY::`, SIP multipart) and typed
2//! variable name enums.
3
4mod core;
5mod esl_array;
6mod sip_call_info;
7mod sip_geolocation;
8mod sip_history_info;
9mod sip_invite;
10mod sip_multipart;
11mod sofia;
12
13/// Split comma-separated entries respecting angle-bracket nesting.
14pub(crate) fn split_comma_entries(raw: &str) -> Vec<&str> {
15    let mut entries = Vec::new();
16    let mut depth = 0u32;
17    let mut start = 0;
18
19    for (i, ch) in raw.char_indices() {
20        match ch {
21            '<' => depth += 1,
22            '>' => depth = depth.saturating_sub(1),
23            ',' if depth == 0 => {
24                entries.push(&raw[start..i]);
25                start = i + 1;
26            }
27            _ => {}
28        }
29    }
30    if start < raw.len() {
31        entries.push(&raw[start..]);
32    }
33
34    entries
35}
36
37pub use self::core::{ChannelVariable, ParseChannelVariableError};
38pub use esl_array::EslArray;
39pub use sip_call_info::{SipCallInfo, SipCallInfoEntry, SipCallInfoError};
40pub use sip_geolocation::{SipGeolocation, SipGeolocationRef};
41pub use sip_history_info::{HistoryInfo, HistoryInfoEntry, HistoryInfoError, HistoryInfoReason};
42
43pub use sip_invite::{ParseSipInviteHeaderError, SipInviteHeader};
44pub use sip_multipart::{MultipartBody, MultipartItem};
45pub use sofia::{ParseSofiaVariableError, SofiaVariable};
46
47/// Trait for typed channel variable name enums.
48///
49/// Implement this on variable name enums to use them with
50/// [`HeaderLookup::variable()`](crate::HeaderLookup::variable) and
51/// [`variable_str()`](crate::HeaderLookup::variable_str).
52/// For variables not covered by any typed enum, use `variable_str()`.
53pub trait VariableName {
54    /// Wire-format variable name (e.g. `"sip_call_id"`).
55    fn as_str(&self) -> &str;
56}
57
58impl VariableName for ChannelVariable {
59    fn as_str(&self) -> &str {
60        ChannelVariable::as_str(self)
61    }
62}
63
64impl VariableName for SofiaVariable {
65    fn as_str(&self) -> &str {
66        SofiaVariable::as_str(self)
67    }
68}
69
70impl VariableName for SipInviteHeader {
71    fn as_str(&self) -> &str {
72        SipInviteHeader::as_str(self)
73    }
74}