cdns-rs 1.2.2

A native Sync/Async Rust implementation of client DNS resolver.
Documentation
/*-
 * cdns-rs - a simple sync/async DNS query library
 * 
 * Copyright (C) 2020  Aleksandr Morozov
 * 
 * Copyright (C) 2025 Aleksandr Morozov
 * 
 * The syslog-rs crate can be redistributed and/or modified
 * under the terms of either of the following licenses:
 *
 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
 *                     
 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
 */

/// This file contains the config file parsers.


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
{
    /// This function should be used when the program which uses this library
    /// requires to override the systems /etc/resolv.conf
    pub 
    fn custom_config(resolv_cfg: &str) -> CDnsResult<Self>
    {
        let ret = Self::parser_resolv_internal(resolv_cfg);

        return ret;
    }
}