icecast_stats/
icecast_stats.rs1use crate::IcecastStatsSource;
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "chrono")]
5use crate::parser::parse_datetime;
6#[cfg(feature = "chrono")]
7use chrono::{DateTime, FixedOffset};
8
9#[derive(Serialize, Deserialize, Debug)]
11pub struct IcecastStatsRoot {
12 pub icestats: IcecastStats,
13}
14
15#[derive(Serialize, Deserialize, Debug, Clone)]
17pub struct IcecastStats {
18 admin: String,
19 #[serde(rename = "banned_IPs")]
20 banned_ips: Option<u32>,
21 client_connections: Option<u32>,
22 clients: Option<u32>,
23 connections: Option<u32>,
24 file_connections: Option<u32>,
25 host: String,
26 listener_connections: Option<u32>,
27 listeners: Option<u32>,
28 location: String,
29 server_id: String,
30 source_client_connections: Option<u32>,
31 source_relay_connections: Option<u32>,
32 source_total_connections: Option<u32>,
33 sources: Option<u32>,
34 stats: Option<u32>,
35 stats_connections: Option<u32>,
36 server_start: Option<String>,
37 server_start_iso8601: Option<String>,
38
39 source: Option<IcecastStatsSourceEnum>,
41}
42
43impl IcecastStats {
44 pub fn admin(&self) -> &String {
50 &self.admin
51 }
52
53 pub fn client_connections(&self) -> &Option<u32> {
56 &self.client_connections
57 }
58
59 pub fn clients(&self) -> &Option<u32> {
61 &self.clients
62 }
63
64 pub fn connections(&self) -> &Option<u32> {
67 &self.connections
68 }
69
70 pub fn file_connections(&self) -> &Option<u32> {
72 &self.file_connections
73 }
74
75 pub fn host(&self) -> &String {
79 &self.host
80 }
81
82 pub fn listener_connections(&self) -> &Option<u32> {
85 &self.listener_connections
86 }
87
88 pub fn listeners(&self) -> &Option<u32> {
90 &self.listeners
91 }
92
93 pub fn location(&self) -> &String {
97 &self.location
98 }
99
100 pub fn server_id(&self) -> &String {
104 &self.server_id
105 }
106
107 pub fn source_client_connections(&self) -> &Option<u32> {
110 &self.source_client_connections
111 }
112
113 pub fn source_relay_connections(&self) -> &Option<u32> {
116 &self.source_relay_connections
117 }
118
119 pub fn source_total_connections(&self) -> &Option<u32> {
122 &self.source_total_connections
123 }
124
125 pub fn sources(&self) -> &Option<u32> {
127 &self.sources
128 }
129
130 pub fn stats(&self) -> &Option<u32> {
132 &self.stats
133 }
134
135 pub fn stats_connections(&self) -> &Option<u32> {
138 &self.stats_connections
139 }
140
141 pub fn server_start(&self) -> Option<&String> {
145 if self.server_start_iso8601.is_some() {
146 return self.server_start_iso8601.as_ref();
147 }
148 self.server_start.as_ref()
149 }
150
151 #[cfg(feature = "chrono")]
154 pub fn server_start_decoded(
155 &self,
156 ) -> Option<Result<DateTime<FixedOffset>, chrono::ParseError>> {
157 self.server_start().clone().map(|x| parse_datetime(&x))
158 }
159
160 pub fn sources_vec(&self) -> Vec<IcecastStatsSource> {
162 match &self.source {
163 Some(source_enum) => match source_enum {
164 IcecastStatsSourceEnum::Single(icecast_stats_source) => {
165 vec![icecast_stats_source.clone()]
166 }
167 IcecastStatsSourceEnum::Multiple(list) => list.clone(),
168 },
169 None => vec![],
170 }
171 }
172}
173
174#[derive(Serialize, Deserialize, Debug, Clone)]
176#[serde(untagged)]
177pub enum IcecastStatsSourceEnum {
178 Single(IcecastStatsSource),
179 Multiple(Vec<IcecastStatsSource>),
180}