use std::path::Path;
use async_trait::async_trait;
use crate::cfg_resolv_parser::{ResolveConfig, OptionFlags};
use crate::error::*;
use super::caches::CacheOperations;
use super::cfg_parsers::{ConfigParser, read_file};
use super::common::{RESOLV_CFG_PATH, RESOLV_CFG_PATH_P};
use super::log::async_log_writer;
impl CacheOperations for ResolveConfig
{
fn is_reload_allowed(&self) -> bool
{
return !self.option_flags.contains(OptionFlags::OPT_NO_RELOAD);
}
}
#[async_trait]
impl ConfigParser<ResolveConfig> for ResolveConfig
{
async
fn parse_config() -> CDnsResult<Self>
{
let file_content = read_file(RESOLV_CFG_PATH).await?;
let mut writer = Writer::new();
let ret = Self::parser_resolv_internal(file_content.as_str(), &mut writer);
async_log_writer(writer).await;
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 async
fn async_custom_config(resolv_cfg: &str) -> CDnsResult<Self>
{
let mut writer = Writer::new();
let ret = Self::parser_resolv_internal(resolv_cfg, &mut writer);
async_log_writer(writer).await;
return ret;
}
}