1use anyhow::Result;
4use reqwest::Client as Reqw;
5use std::net::IpAddr;
6use std::time::Duration;
7
8pub mod dynu;
9pub mod dynv6;
10pub use dynu::Dynu;
13pub use dynv6::Dynv6;
14
15pub trait SetProvider {
17 const DEDUPLICATES_RECORDS: bool = true;
18 async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
19 async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
20}
21
22pub trait StackProvider {
25 const DEDUPLICATES_RECORDS: bool = false;
26 async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
27 async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
28}
29
30pub trait UpdatingProvider {
32 async fn update_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
33}
34
35pub const fn record_type(ipaddr: IpAddr) -> &'static str {
36 if ipaddr.is_ipv4() {
37 "A"
38 } else {
39 "AAAA"
40 }
41}
42
43pub fn new_reqw() -> Result<Reqw> {
44 let r = Reqw::builder()
45 .user_agent("rrdnsd")
46 .timeout(Duration::from_secs(30))
47 .pool_max_idle_per_host(0)
48 .build()?;
49 Ok(r)
50}