// Prdoduce a YAML formatted string given a data structure known to Serde
fn to_yaml_string(self: &Recursorsettings) -> Result<String>;
- fn get_value(self: &Recursorsettings, field: &Vec<String>, defaults: &str) -> Result<String>;
+ fn get_value(self: &Recursorsettings, field: &[String], defaults: &str) -> Result<String>;
// When doing a conversion of old-style to YAML style we use a vector of OldStyle structs
fn map_to_yaml_string(map: &Vec<OldStyle>) -> Result<String>;
fn forward_zones_to_yaml_string(vec: &Vec<ForwardZone>) -> Result<String>;
for addr_str in vec {
let mut wrong = false;
let sa = SocketAddr::from_str(addr_str);
- if sa.is_err() {
+ if let Ok(address) = sa {
+ if local.is_ipv4() != address.is_ipv4() || local.is_ipv6() != address.is_ipv6() {
+ wrong = true;
+ }
+ }
+ else {
let ip = IpAddr::from_str(addr_str);
if ip.is_err() {
// It is likely a name
if local.is_ipv4() != ip.is_ipv4() || local.is_ipv6() != ip.is_ipv6() {
wrong = true;
}
- } else {
- let sa = sa.unwrap();
- if local.is_ipv4() != sa.is_ipv4() || local.is_ipv6() != sa.is_ipv6() {
- wrong = true;
- }
}
if wrong {
let msg = format!(
Err(std::io::Error::other(field[0].to_owned() + ": not a map"))
}
- pub fn get_value(&self, field: &Vec<String>, defaults: &str) -> Result<String, std::io::Error> {
+ pub fn get_value(&self, field: &[String], defaults: &str) -> Result<String, std::io::Error> {
let value = serde_yaml::to_value(self);
let value = match value {
Ok(value) => value,
Err(error) => return Err(std::io::Error::other(error.to_string()))
};
match Self::get_value1(&value, field) {
- Ok(result) => Ok(result),
+ Ok(yaml) => Ok(yaml),
Err(_) => {
let defaults_value: serde_yaml::Value = serde_yaml::from_str(defaults).unwrap();
let yaml = Self::get_value1(&defaults_value, field);
match yaml {
- Ok(yaml) => Ok("# Not explicitly set, default value is:\n".to_owned() + &yaml),
- Err(x) => Err(x)
+ Ok(yaml) => Ok("# Not explicitly set, default value(s) listed below:\n".to_owned() + &yaml),
+ x => x
}
}
}
let data: Result<ApiZones, serde_yaml::Error> =
serde_yaml::from_reader(BufReader::new(file));
match data {
- Err(error) => return Err(std::io::Error::new(ErrorKind::Other, error.to_string())),
+ Err(error) => return Err(std::io::Error::other(error.to_string())),
Ok(yaml) => yaml,
}
}
let file = File::create(tmpfile.as_str())?;
let mut buffered_writer = BufWriter::new(&file);
if let Err(error) = serde_yaml::to_writer(&mut buffered_writer, &zones) {
- return Err(std::io::Error::new(ErrorKind::Other, error.to_string()));
+ return Err(std::io::Error::other(error.to_string()));
}
buffered_writer.flush()?;
file.sync_all()?;
use hyper::service::service_fn;
use hyper::{body::Incoming as IncomingBody, header, Method, Request, Response, StatusCode};
use hyper_util::rt::TokioIo;
-use std::io::ErrorKind;
use std::str::FromStr;
use std::sync::Arc;
use tokio::net::TcpListener;
let mut server_config = rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(certs, key)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
+ .map_err(|e| std::io::Error::other(e.to_string()))?;
server_config.alpn_protocols = vec![b"http/1.1".to_vec(), b"http/1.0".to_vec()]; // b"h2".to_vec()
let tls_acceptor = tokio_rustls::TlsAcceptor::from(Arc::new(server_config));
// We start a loop to continuously accept incoming connections
Ok(val) => val,
Err(err) => {
let msg = format!("`{}' is not a IP:port combination: {}", addr_str, err);
- return Err(std::io::Error::new(ErrorKind::Other, msg));
+ return Err(std::io::Error::other(msg));
}
};
}],
);
let msg = format!("Unable to bind web socket: {}", err);
- return Err(std::io::Error::new(ErrorKind::Other, msg));
+ return Err(std::io::Error::other(msg));
}
}
}
fn load_certs(filename: &str) -> std::io::Result<Vec<pki_types::CertificateDer<'static>>> {
// Open certificate file.
let certfile = std::fs::File::open(filename).map_err(|e| {
- std::io::Error::new(
- std::io::ErrorKind::Other,
+ std::io::Error::other(
format!("Failed to open {}: {}", filename, e),
)
})?;
fn load_private_key(filename: &str) -> std::io::Result<pki_types::PrivateKeyDer<'static>> {
// Open keyfile.
let keyfile = std::fs::File::open(filename).map_err(|e| {
- std::io::Error::new(
- std::io::ErrorKind::Other,
+ std::io::Error::other(
format!("Failed to open {}: {}", filename, e),
)
})?;
match rustls_pemfile::private_key(&mut reader) {
Ok(Some(pkey)) => Ok(pkey),
Ok(None) => Err(
- std::io::Error::new(
- std::io::ErrorKind::Other,
+ std::io::Error::other(
format!("Failed to parse private key from {}", filename),
)),
Err(e) => Err(e)
auto settings = g_yamlStruct.lock();
rust::Vec<::rust::String> field;
stringtok(field, *begin, ".");
+ rust::Slice<const ::rust::String> slice{field};
try {
- auto yaml = settings->get_value(field, pdns::settings::rec::defaultsToYaml(false));
+ auto yaml = settings->get_value(slice, pdns::settings::rec::defaultsToYaml(false));
return {0, std::string(yaml)};
}
catch (const std::exception& stdex) {
}
try {
pdns::checked_stoi_into(SyncRes::s_event_trace_enabled, *begin);
+ if (g_yamlSettings) {
+ g_yamlStruct.lock()->recursor.event_trace_enabled = SyncRes::s_event_trace_enabled;
+ }
return {0, "New event trace enabled value: " + std::to_string(SyncRes::s_event_trace_enabled) + "\n"};
}
catch (const std::exception& e) {