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