cdns_rs/sync/
cfg_resolv_parser.rs

1/*-
2 * cdns-rs - a simple sync/async DNS query library
3 * 
4 * Copyright (C) 2020  Aleksandr Morozov
5 * 
6 * Copyright (C) 2025 Aleksandr Morozov
7 * 
8 * The syslog-rs crate can be redistributed and/or modified
9 * under the terms of either of the following licenses:
10 *
11 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
12 *                     
13 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
14 */
15
16/// This file contains the config file parsers.
17
18
19use 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    /// This function should be used when the program which uses this library
64    /// requires to override the systems /etc/resolv.conf
65    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