cdns_rs/a_sync/
cfg_host_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 async_trait::async_trait;
22
23use crate::a_sync::interface::UnifiedFs;
24use crate::cfg_host_parser::HostConfig;
25use crate::common::{HOST_CFG_PATH, HOST_CFG_PATH_P};
26use crate::error::*;
27
28
29use super::caches::CacheOperations;
30use super::cfg_parsers::{ConfigParser, read_file};
31
32/// An /etc/hosts file parser
33
34
35impl CacheOperations for HostConfig
36{
37    fn is_reload_allowed(&self) -> bool 
38    {
39        return true;
40    }
41}
42
43
44impl ConfigParser<HostConfig> for HostConfig
45{
46    async
47    fn parse_config<UFS: UnifiedFs>() -> CDnsResult<Self>
48    {
49        let file_content = read_file::<UFS>(HOST_CFG_PATH).await?;
50        
51        let ret = Self::parse_host_file_internal(file_content);
52
53        return ret;
54    }
55
56    fn get_file_path() -> &'static Path
57    {
58        return &HOST_CFG_PATH_P;
59    }
60
61    fn is_default(&self) -> bool
62    {
63        return self.is_empty();
64    }
65}
66