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