cdns_rs/a_sync/
cfg_resolv_parser.rs1use std::path::Path;
20
21use async_trait::async_trait;
22
23
24use crate::a_sync::interface::UnifiedFs;
25use crate::cfg_resolv_parser::{ResolveConfig, OptionFlags};
26use crate::common::{RESOLV_CFG_PATH, RESOLV_CFG_PATH_P};
27use crate::error::*;
28
29use super::caches::CacheOperations;
30use super::cfg_parsers::{ConfigParser, read_file};
31
32
33
34impl CacheOperations for ResolveConfig
35{
36 fn is_reload_allowed(&self) -> bool
37 {
38 return !self.option_flags.contains(OptionFlags::OPT_NO_RELOAD);
39 }
40}
41
42
43impl ConfigParser<ResolveConfig> for ResolveConfig
44{
45 async
46 fn parse_config<UFS: UnifiedFs>() -> CDnsResult<Self>
47 {
48 let file_content = read_file::<UFS>(RESOLV_CFG_PATH).await?;
49
50 let ret = Self::parser_resolv_internal(file_content.as_str());
51
52 return ret;
53 }
54
55 fn get_file_path() -> &'static Path
56 {
57 return &RESOLV_CFG_PATH_P;
58 }
59
60 fn is_default(&self) -> bool
61 {
62 return self.nameservers.is_empty();
63 }
64}
65
66impl ResolveConfig
67{
68 pub async
71 fn async_custom_config(resolv_cfg: &str) -> CDnsResult<Self>
72 {
73 return Self::parser_resolv_internal(resolv_cfg);
74 }
75}
76
77