From: Fred Morcos Date: Tue, 12 Sep 2023 21:24:12 +0000 (+0200) Subject: Revert "Rec: Settings Rust bridge prefer slices over Vec references" X-Git-Tag: rec-5.0.0-alpha1~1^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5a2a8db2bd905d02f0ec2aa0befa9c697e8a39d5;p=thirdparty%2Fpdns.git Revert "Rec: Settings Rust bridge prefer slices over Vec references" This reverts commit ea0681a158aa8bc60fdbc8fe39b41d60ae800629. --- diff --git a/pdns/recursordist/rec_control.cc b/pdns/recursordist/rec_control.cc index 79315a3e63..6264ae5122 100644 --- a/pdns/recursordist/rec_control.cc +++ b/pdns/recursordist/rec_control.cc @@ -153,7 +153,7 @@ static std::string showForwardFileYAML(const ::rust::string& rfilename) msg += std::string(yaml); msg += "# Validation result: "; try { - pdns::rust::settings::rec::validate_forward_zones("forward_zones", {forwards.data(), forwards.size()}); + pdns::rust::settings::rec::validate_forward_zones("forward_zones", forwards); msg += "OK"; } catch (const rust::Error& err) { @@ -163,7 +163,7 @@ static std::string showForwardFileYAML(const ::rust::string& rfilename) return msg; } -static std::string showAllowYAML(const ::rust::String& rfilename, const string& section, const string& key, const std::function)>& func) +static std::string showAllowYAML(const ::rust::String& rfilename, const string& section, const string& key, const std::function&)>& func) { std::string msg; if (rfilename.empty() || boost::ends_with(rfilename, ".yml")) { @@ -178,7 +178,7 @@ static std::string showAllowYAML(const ::rust::String& rfilename, const string& msg += std::string(yaml); msg += "# Validation result: "; try { - func(key, {allows.data(), allows.size()}); + func(key, allows); msg += "OK"; } catch (const rust::Error& err) { diff --git a/pdns/recursordist/settings/cxxsupport.cc b/pdns/recursordist/settings/cxxsupport.cc index 46ba962f0a..84c3f1c455 100644 --- a/pdns/recursordist/settings/cxxsupport.cc +++ b/pdns/recursordist/settings/cxxsupport.cc @@ -177,7 +177,7 @@ void pdns::settings::rec::readYamlAllowFromFile(const std::string& filename, ::r } auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_allow_from(data); - pdns::rust::settings::rec::validate_allow_from(filename, {yamlvec.data(), yamlvec.size()}); + pdns::rust::settings::rec::validate_allow_from(filename, yamlvec); vec = yamlvec; } @@ -191,7 +191,7 @@ void pdns::settings::rec::readYamlForwardZonesFile(const std::string& filename, } auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_forward_zones(data); - pdns::rust::settings::rec::validate_forward_zones("forward_zones", {yamlvec.data(), yamlvec.size()}); + pdns::rust::settings::rec::validate_forward_zones("forward_zones", yamlvec); vec = yamlvec; } @@ -205,7 +205,7 @@ void pdns::settings::rec::readYamlAllowNotifyForFile(const std::string& filename } auto data = string(std::istreambuf_iterator(file), std::istreambuf_iterator()); auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_allow_notify_for(data); - pdns::rust::settings::rec::validate_allow_notify_for("allow-notify-for", {yamlvec.data(), yamlvec.size()}); + pdns::rust::settings::rec::validate_allow_notify_for("allow-notify-for", yamlvec); vec = yamlvec; } diff --git a/pdns/recursordist/settings/rust-bridge-in.rs b/pdns/recursordist/settings/rust-bridge-in.rs index ff82a1c585..1ee664c173 100644 --- a/pdns/recursordist/settings/rust-bridge-in.rs +++ b/pdns/recursordist/settings/rust-bridge-in.rs @@ -95,11 +95,11 @@ extern "Rust" { fn validate(self: &ApiZones, field: &str) -> Result<()>; // Helper functions to call the proper validate function on vectors of various kinds - fn validate_auth_zones(field: &str, vec: &[AuthZone]) -> Result<()>; - fn validate_forward_zones(field: &str, vec: &[ForwardZone]) -> Result<()>; - fn validate_allow_for(field: &str, vec: &[String]) -> Result<()>; - fn validate_allow_notify_for(field: &str, vec: &[String]) -> Result<()>; - fn validate_allow_from(field: &str, vec: &[String]) -> Result<()>; + fn validate_auth_zones(field: &str, vec: &Vec) -> Result<()>; + fn validate_forward_zones(field: &str, vec: &Vec) -> Result<()>; + fn validate_allow_for(field: &str, vec: &Vec) -> Result<()>; + fn validate_allow_notify_for(field: &str, vec: &Vec) -> Result<()>; + fn validate_allow_from(field: &str, vec: &Vec) -> Result<()>; // The functions to maintain REST API managed zones fn api_read_zones(path: &str) -> Result>; diff --git a/pdns/recursordist/settings/rust/src/bridge.rs b/pdns/recursordist/settings/rust/src/bridge.rs index b08b9ed019..80d1589e51 100644 --- a/pdns/recursordist/settings/rust/src/bridge.rs +++ b/pdns/recursordist/settings/rust/src/bridge.rs @@ -210,13 +210,13 @@ impl AuthZone { } } -pub fn validate_auth_zones(field: &str, vec: &[AuthZone]) -> Result<(), ValidationError> { +pub fn validate_auth_zones(field: &str, vec: &Vec) -> Result<(), ValidationError> { validate_vec(field, vec, |field, element| element.validate(field)) } pub fn validate_forward_zones( field: &str, - vec: &[ForwardZone], + vec: &Vec, ) -> Result<(), ValidationError> { validate_vec(field, vec, |field, element| element.validate(field)) } @@ -270,7 +270,7 @@ pub fn allow_from_to_yaml_string_incoming( serde_yaml::to_string(&outerval) } -pub fn validate_allow_from(field: &str, vec: &[String]) -> Result<(), ValidationError> { +pub fn validate_allow_from(field: &str, vec: &Vec) -> Result<(), ValidationError> { validate_vec(field, vec, validate_subnet) } @@ -280,11 +280,11 @@ pub fn allow_for_to_yaml_string(vec: &Vec) -> Result Result<(), ValidationError> { +pub fn validate_allow_for(field: &str, vec: &Vec) -> Result<(), ValidationError> { validate_vec(field, vec, validate_name) } -pub fn validate_allow_notify_for(field: &str, vec: &[String]) -> Result<(), ValidationError> { +pub fn validate_allow_notify_for(field: &str, vec: &Vec) -> Result<(), ValidationError> { validate_vec(field, vec, validate_name) } diff --git a/pdns/recursordist/ws-recursor.cc b/pdns/recursordist/ws-recursor.cc index 5ec0c01c57..2737f78ec0 100644 --- a/pdns/recursordist/ws-recursor.cc +++ b/pdns/recursordist/ws-recursor.cc @@ -103,7 +103,7 @@ static void apiServerConfigACL(const std::string& aclType, HttpRequest* req, Htt } try { - ::pdns::rust::settings::rec::validate_allow_from(aclType, {vec.data(), vec.size()}); + ::pdns::rust::settings::rec::validate_allow_from(aclType, vec); } catch (const ::rust::Error& e) { throw ApiException(string("Unable to convert: ") + e.what());