std::string tmp(str.data(), str.length());
return QType::chartocode(tmp.c_str());
}
+
+bool pdns::rust::settings::rec::isValidHostname(::rust::Str str)
+{
+ try {
+ auto name = DNSName(string(str));
+ return name.isHostname();
+ }
+ catch (...) {
+ return false;
+ }
+}
unsafe extern "C++" {
include!("bridge.hh");
fn qTypeStringToCode(name: &str) -> u16;
+ fn isValidHostname(name: &str) -> bool;
}
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
-[[package]]
-name = "hostname-validator"
-version = "1.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f558a64ac9af88b5ba400d99b579451af0d39c6d360980045b91aac966d705e2"
-
[[package]]
name = "indexmap"
version = "2.1.0"
"base64",
"cxx",
"cxx-build",
- "hostname-validator",
"ipnet",
"once_cell",
"serde",
serde_yaml = "0.9"
ipnet = "2.8"
once_cell = "1.18.0"
-hostname-validator = "1.1.1" # This is temporary. PR 13819 has the infra to call C++ from, so we can arrange for DNSName::ishostname() to be called instead of importing another crate after that one is merged.
base64 = "0.21"
[build-dependencies]
fn main() {
cxx_build::bridge("src/lib.rs")
- // .file("src/source.cc") at the moment no C++ code callable from Rust
+ // .file("src/source.cc") Code callable from Rust is in ../cxxsupport.cc
.flag_if_supported("-std=c++17")
.flag("-Isrc")
.compile("settings");
namespace pdns::rust::settings::rec
{
uint16_t qTypeStringToCode(::rust::Str str);
+bool isValidHostname(::rust::Str str);
}
pub fn validate_socket_address_or_name(field: &str, val: &String) -> Result<(), ValidationError> {
let sa = validate_socket_address(field, val);
if sa.is_err() {
- if !hostname_validator::is_valid(val) {
+ if !isValidHostname(val) {
let parts: Vec<&str> = val.split(':').collect();
if parts.len() != 2
- || !hostname_validator::is_valid(parts[0])
+ || !isValidHostname(parts[0])
|| !is_port_number(parts[1])
{
let msg = format!(