freeswitch_log_parser/message/
kind.rs1use std::fmt;
4
5use crate::codec::CodecMedia;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum SdpDirection {
10 Local,
11 LocalRing,
13 Remote,
14 Unknown,
16}
17
18#[non_exhaustive]
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum SipInviteDirection {
22 Receiving,
24 Sending,
26}
27
28#[non_exhaustive]
30#[derive(Debug, Clone, Copy, PartialEq, Eq)]
31pub enum DtmfSource {
32 Rtp,
34 Channel,
36 SipInfo,
38}
39
40impl fmt::Display for DtmfSource {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 match self {
43 DtmfSource::Rtp => f.pad("rtp"),
44 DtmfSource::Channel => f.pad("channel"),
45 DtmfSource::SipInfo => f.pad("sip-info"),
46 }
47 }
48}
49
50impl fmt::Display for SdpDirection {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match self {
53 SdpDirection::Local => f.pad("local"),
54 SdpDirection::LocalRing => f.pad("local-ring"),
55 SdpDirection::Remote => f.pad("remote"),
56 SdpDirection::Unknown => f.pad("unknown"),
57 }
58 }
59}
60
61#[non_exhaustive]
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub enum MessageKind {
68 Execute {
70 depth: u32,
71 channel: String,
72 application: String,
73 arguments: String,
74 },
75 Dialplan { channel: String, detail: String },
77 ChannelData,
79 ChannelField { name: String, value: String },
81 Variable { name: String, value: String },
84 SdpMarker { direction: SdpDirection },
86 StateChange { detail: String },
88 CodecNegotiation { media: CodecMedia },
90 Media { detail: String },
92 ChannelLifecycle { detail: String },
94 SipInvite {
102 direction: SipInviteDirection,
103 profile: String,
105 call_id: Option<String>,
110 },
111 EventSocket { detail: String },
113 Dtmf {
116 source: DtmfSource,
118 digit: char,
120 duration_ms: Option<u32>,
122 },
123 General,
125 FileChange,
127 DateChange,
129}
130
131impl MessageKind {
132 pub const ALL_LABELS: &[&str] = &[
134 "execute",
135 "dialplan",
136 "channel-data",
137 "channel-field",
138 "variable",
139 "sdp-marker",
140 "state-change",
141 "codec-negotiation",
142 "media",
143 "channel-lifecycle",
144 "sip-invite",
145 "event-socket",
146 "dtmf",
147 "general",
148 "file-change",
149 "date-change",
150 ];
151
152 pub fn label(&self) -> &'static str {
154 match self {
155 MessageKind::Execute { .. } => "execute",
156 MessageKind::Dialplan { .. } => "dialplan",
157 MessageKind::ChannelData => "channel-data",
158 MessageKind::ChannelField { .. } => "channel-field",
159 MessageKind::Variable { .. } => "variable",
160 MessageKind::SdpMarker { .. } => "sdp-marker",
161 MessageKind::StateChange { .. } => "state-change",
162 MessageKind::CodecNegotiation { .. } => "codec-negotiation",
163 MessageKind::Media { .. } => "media",
164 MessageKind::ChannelLifecycle { .. } => "channel-lifecycle",
165 MessageKind::SipInvite { .. } => "sip-invite",
166 MessageKind::EventSocket { .. } => "event-socket",
167 MessageKind::Dtmf { .. } => "dtmf",
168 MessageKind::General => "general",
169 MessageKind::FileChange => "file-change",
170 MessageKind::DateChange => "date-change",
171 }
172 }
173}
174
175impl fmt::Display for MessageKind {
176 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
177 match self {
178 MessageKind::Execute { application, .. } => write!(f, "execute({})", application),
179 MessageKind::Dialplan { .. } => f.pad("dialplan"),
180 MessageKind::ChannelData => f.pad("channel-data"),
181 MessageKind::ChannelField { name, .. } => write!(f, "field({})", name),
182 MessageKind::Variable { name, .. } => write!(f, "var({})", name),
183 MessageKind::SdpMarker { direction } => write!(f, "sdp({})", direction),
184 MessageKind::StateChange { .. } => f.pad("state-change"),
185 MessageKind::CodecNegotiation { media } => {
186 f.pad(&format!("codec-negotiation({media})"))
187 }
188 MessageKind::Media { .. } => f.pad("media"),
189 MessageKind::ChannelLifecycle { .. } => f.pad("channel-lifecycle"),
190 MessageKind::SipInvite { .. } => f.pad("sip-invite"),
191 MessageKind::EventSocket { .. } => f.pad("event-socket"),
192 MessageKind::Dtmf {
193 source,
194 digit,
195 duration_ms,
196 } => match duration_ms {
197 Some(ms) => write!(f, "dtmf({source}:{digit}:{ms}ms)"),
198 None => write!(f, "dtmf({source}:{digit})"),
199 },
200 MessageKind::General => f.pad("general"),
201 MessageKind::FileChange => f.pad("file-change"),
202 MessageKind::DateChange => f.pad("date-change"),
203 }
204 }
205}