cdns_rs/a_sync/
cfg_resolv_parser.rs1use std::path::Path;
28
29use async_trait::async_trait;
30
31
32use crate::cfg_resolv_parser::{ResolveConfig, OptionFlags};
33use crate::error::*;
34
35use super::caches::CacheOperations;
36use super::cfg_parsers::{ConfigParser, read_file};
37use super::common::{RESOLV_CFG_PATH, RESOLV_CFG_PATH_P};
38use super::log::async_log_writer;
39
40
41impl CacheOperations for ResolveConfig
42{
43 fn is_reload_allowed(&self) -> bool
44 {
45 return !self.option_flags.contains(OptionFlags::OPT_NO_RELOAD);
46 }
47}
48
49
50#[async_trait]
51impl ConfigParser<ResolveConfig> for ResolveConfig
52{
53 async
54 fn parse_config() -> CDnsResult<Self>
55 {
56 let file_content = read_file(RESOLV_CFG_PATH).await?;
57
58 let mut writer = Writer::new();
59
60 let ret = Self::parser_resolv_internal(file_content.as_str(), &mut writer);
61
62 async_log_writer(writer).await;
63
64 return ret;
65 }
66
67 fn get_file_path() -> &'static Path
68 {
69 return &RESOLV_CFG_PATH_P;
70 }
71
72 fn is_default(&self) -> bool
73 {
74 return self.nameservers.is_empty();
75 }
76}
77
78impl ResolveConfig
79{
80 pub async
83 fn async_custom_config(resolv_cfg: &str) -> CDnsResult<Self>
84 {
85 let mut writer = Writer::new();
86
87 let ret = Self::parser_resolv_internal(resolv_cfg, &mut writer);
88
89 async_log_writer(writer).await;
90
91 return ret;
92 }
93}
94
95