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