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 },
83 SdpMarker { direction: SdpDirection },
85 StateChange { detail: String },
87 CodecNegotiation { media: CodecMedia },
89 Media { detail: String },
91 ChannelLifecycle { detail: String },
93 SipInvite {
101 direction: SipInviteDirection,
102 profile: String,
104 call_id: Option<String>,
109 },
110 EventSocket { detail: String },
112 Dtmf {
115 source: DtmfSource,
117 digit: char,
119 duration_ms: Option<u32>,
121 },
122 General,
124 FileChange,
126 DateChange,
128}
129
130impl MessageKind {
131 pub const ALL_LABELS: &[&str] = &[
133 "execute",
134 "dialplan",
135 "channel-data",
136 "channel-field",
137 "variable",
138 "sdp-marker",
139 "state-change",
140 "codec-negotiation",
141 "media",
142 "channel-lifecycle",
143 "sip-invite",
144 "event-socket",
145 "dtmf",
146 "general",
147 "file-change",
148 "date-change",
149 ];
150
151 pub fn label(&self) -> &'static str {
153 match self {
154 MessageKind::Execute { .. } => "execute",
155 MessageKind::Dialplan { .. } => "dialplan",
156 MessageKind::ChannelData => "channel-data",
157 MessageKind::ChannelField { .. } => "channel-field",
158 MessageKind::Variable { .. } => "variable",
159 MessageKind::SdpMarker { .. } => "sdp-marker",
160 MessageKind::StateChange { .. } => "state-change",
161 MessageKind::CodecNegotiation { .. } => "codec-negotiation",
162 MessageKind::Media { .. } => "media",
163 MessageKind::ChannelLifecycle { .. } => "channel-lifecycle",
164 MessageKind::SipInvite { .. } => "sip-invite",
165 MessageKind::EventSocket { .. } => "event-socket",
166 MessageKind::Dtmf { .. } => "dtmf",
167 MessageKind::General => "general",
168 MessageKind::FileChange => "file-change",
169 MessageKind::DateChange => "date-change",
170 }
171 }
172}
173
174impl fmt::Display for MessageKind {
175 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176 match self {
177 MessageKind::Execute { application, .. } => write!(f, "execute({})", application),
178 MessageKind::Dialplan { .. } => f.pad("dialplan"),
179 MessageKind::ChannelData => f.pad("channel-data"),
180 MessageKind::ChannelField { name, .. } => write!(f, "field({})", name),
181 MessageKind::Variable { name, .. } => write!(f, "var({})", name),
182 MessageKind::SdpMarker { direction } => write!(f, "sdp({})", direction),
183 MessageKind::StateChange { .. } => f.pad("state-change"),
184 MessageKind::CodecNegotiation { media } => {
185 f.pad(&format!("codec-negotiation({media})"))
186 }
187 MessageKind::Media { .. } => f.pad("media"),
188 MessageKind::ChannelLifecycle { .. } => f.pad("channel-lifecycle"),
189 MessageKind::SipInvite { .. } => f.pad("sip-invite"),
190 MessageKind::EventSocket { .. } => f.pad("event-socket"),
191 MessageKind::Dtmf {
192 source,
193 digit,
194 duration_ms,
195 } => match duration_ms {
196 Some(ms) => write!(f, "dtmf({source}:{digit}:{ms}ms)"),
197 None => write!(f, "dtmf({source}:{digit})"),
198 },
199 MessageKind::General => f.pad("general"),
200 MessageKind::FileChange => f.pad("file-change"),
201 MessageKind::DateChange => f.pad("date-change"),
202 }
203 }
204}