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 async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
18 async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
19}
20
21pub trait StackProvider {
24 async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
25 async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
26}
27
28pub trait UpdatingProvider {
30 async fn update_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
31}
32
33pub const fn record_type(ipaddr: IpAddr) -> &'static str {
34 if ipaddr.is_ipv4() {
35 "A"
36 } else {
37 "AAAA"
38 }
39}
40
41pub fn new_reqw() -> Result<Reqw> {
42 let r = Reqw::builder()
43 .user_agent("rrdnsd")
44 .timeout(Duration::from_secs(30))
45 .pool_max_idle_per_host(0)
46 .build()?;
47 Ok(r)
48}