1use std::{fmt::Display, str::FromStr};
9
10pub const DEFAULT_VERIFY_CONNECTION_LIMITER_INTERVAL: u64 = 24 * 60 * 60; use crate::PushError;
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
22pub enum BridgeType {
23 #[default]
24 Fcm,
25 Adm,
26 Apns,
27}
28
29impl Display for BridgeType {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 write!(
32 f,
33 "{}",
34 match self {
35 BridgeType::Adm => "adm",
36 BridgeType::Apns => "apns",
37 BridgeType::Fcm => "fcm",
38 }
39 )
40 }
41}
42#[derive(Clone, Debug)]
43pub struct PushConfiguration {
44 pub server_host: String,
46
47 pub http_protocol: Protocol,
49
50 pub bridge_type: BridgeType,
52
53 pub sender_id: String,
55
56 pub database_path: String,
58
59 pub verify_connection_rate_limiter: Option<u64>,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
66pub enum Protocol {
67 #[default]
68 Https,
69 Http,
70}
71
72impl Display for Protocol {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74 write!(
75 f,
76 "{}",
77 match self {
78 Protocol::Http => "http",
79 Protocol::Https => "https",
80 }
81 )
82 }
83}
84
85impl FromStr for Protocol {
86 type Err = PushError;
87
88 fn from_str(s: &str) -> Result<Self, Self::Err> {
89 Ok(match s {
90 "http" => Protocol::Http,
91 "https" => Protocol::Https,
92 _ => return Err(PushError::GeneralError("Invalid protocol".to_string())),
93 })
94 }
95}
96
97#[cfg(test)]
98impl Default for PushConfiguration {
99 fn default() -> PushConfiguration {
100 PushConfiguration {
101 server_host: String::from("push.services.mozilla.com"),
102 http_protocol: Protocol::Https,
103 bridge_type: Default::default(),
104 sender_id: String::from(""),
105 database_path: String::from(""),
106 verify_connection_rate_limiter: Some(DEFAULT_VERIFY_CONNECTION_LIMITER_INTERVAL),
107 }
108 }
109}