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 2025 Aleksandr Morozov
7 *
8 * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
9 * the European Commission - subsequent versions of the EUPL (the "Licence").
10 *
11 * You may not use this work except in compliance with the Licence.
12 *
13 * You may obtain a copy of the Licence at:
14 *
15 * https://joinup.ec.europa.eu/software/page/eupl
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20 * Licence for the specific language governing permissions and limitations
21 * under the Licence.
22 */
23
24/// This file contains the config file parsers.
25
26
27use std::path::Path;
28
29use async_trait::async_trait;
30
31use crate::a_sync::interface::UnifiedFs;
32use crate::cfg_host_parser::HostConfig;
33use crate::common::{HOST_CFG_PATH, HOST_CFG_PATH_P};
34use crate::error::*;
35
36
37use super::caches::CacheOperations;
38use super::cfg_parsers::{ConfigParser, read_file};
39
40/// An /etc/hosts file parser
41
42
43impl CacheOperations for HostConfig
44{
45 fn is_reload_allowed(&self) -> bool
46 {
47 return true;
48 }
49}
50
51
52impl ConfigParser<HostConfig> for HostConfig
53{
54 async
55 fn parse_config<UFS: UnifiedFs>() -> CDnsResult<Self>
56 {
57 let file_content = read_file::<UFS>(HOST_CFG_PATH).await?;
58
59 let ret = Self::parse_host_file_internal(file_content);
60
61 return ret;
62 }
63
64 fn get_file_path() -> &'static Path
65 {
66 return &HOST_CFG_PATH_P;
67 }
68
69 fn is_default(&self) -> bool
70 {
71 return self.is_empty();
72 }
73}
74