use std::path::Path;
use crate::cfg_resolv_parser::{ResolveConfig, OptionFlags};
use crate::error::*;
use crate::common::{RESOLV_CFG_PATH, RESOLV_CFG_PATH_P};
use super::caches::CacheOperations;
use super::cfg_parsers::{ConfigParser, read_file};
impl CacheOperations for ResolveConfig
{
fn is_reload_allowed(&self) -> bool
{
return !self.option_flags.contains(OptionFlags::OPT_NO_RELOAD);
}
}
impl ConfigParser<ResolveConfig> for ResolveConfig
{
fn parse_config() -> CDnsResult<Self>
{
let file_content = read_file(RESOLV_CFG_PATH)?;
let ret = Self::parser_resolv_internal(file_content.as_str());
return ret;
}
fn get_file_path() -> &'static Path
{
return &RESOLV_CFG_PATH_P;
}
fn is_default(&self) -> bool
{
return self.nameservers.is_empty();
}
}
impl ResolveConfig
{
pub
fn custom_config(resolv_cfg: &str) -> CDnsResult<Self>
{
let ret = Self::parser_resolv_internal(resolv_cfg);
return ret;
}
}