]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Rec: Settings Rust bridge prefer slices over Vec references
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 12 Sep 2023 12:46:18 +0000 (14:46 +0200)
committerFred Morcos <fred.morcos@open-xchange.com>
Tue, 12 Sep 2023 14:01:28 +0000 (16:01 +0200)
pdns/recursordist/rec_control.cc
pdns/recursordist/settings/cxxsupport.cc
pdns/recursordist/settings/rust-bridge-in.rs
pdns/recursordist/settings/rust/src/bridge.rs
pdns/recursordist/ws-recursor.cc

index 6264ae51220a7689fbab2ac05cb60dc47ea44429..79315a3e63523fc0d6d9371d6a175f5c202aa201 100644 (file)
@@ -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);
+    pdns::rust::settings::rec::validate_forward_zones("forward_zones", {forwards.data(), forwards.size()});
     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<void(const ::rust::String&, const ::rust::Vec<::rust::String>&)>& func)
+static std::string showAllowYAML(const ::rust::String& rfilename, const string& section, const string& key, const std::function<void(const ::rust::String&, ::rust::Slice<::rust::String const>)>& 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);
+    func(key, {allows.data(), allows.size()});
     msg += "OK";
   }
   catch (const rust::Error& err) {
index 84c3f1c455bef7a77fb333186e73109d284f5260..46ba962f0afa59e1e7aaca65d7d63ae0346bb33d 100644 (file)
@@ -177,7 +177,7 @@ void pdns::settings::rec::readYamlAllowFromFile(const std::string& filename, ::r
   }
   auto data = string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
   auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_allow_from(data);
-  pdns::rust::settings::rec::validate_allow_from(filename, yamlvec);
+  pdns::rust::settings::rec::validate_allow_from(filename, {yamlvec.data(), yamlvec.size()});
   vec = yamlvec;
 }
 
@@ -191,7 +191,7 @@ void pdns::settings::rec::readYamlForwardZonesFile(const std::string& filename,
   }
   auto data = string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
   auto yamlvec = pdns::rust::settings::rec::parse_yaml_string_to_forward_zones(data);
-  pdns::rust::settings::rec::validate_forward_zones("forward_zones", yamlvec);
+  pdns::rust::settings::rec::validate_forward_zones("forward_zones", {yamlvec.data(), yamlvec.size()});
   vec = yamlvec;
 }
 
@@ -205,7 +205,7 @@ void pdns::settings::rec::readYamlAllowNotifyForFile(const std::string& filename
   }
   auto data = string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
   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);
+  pdns::rust::settings::rec::validate_allow_notify_for("allow-notify-for", {yamlvec.data(), yamlvec.size()});
   vec = yamlvec;
 }
 
index 1ee664c173cfb8540308d04e833650984d54f4ad..ff82a1c585dfceb3b111975c1ffd2b33e6019c84 100644 (file)
@@ -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: &Vec<AuthZone>) -> Result<()>;
-    fn validate_forward_zones(field: &str, vec: &Vec<ForwardZone>) -> Result<()>;
-    fn validate_allow_for(field: &str, vec: &Vec<String>) -> Result<()>;
-    fn validate_allow_notify_for(field: &str, vec: &Vec<String>) -> Result<()>;
-    fn validate_allow_from(field: &str, vec: &Vec<String>) -> Result<()>;
+    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<()>;
 
     // The functions to maintain REST API managed zones
     fn api_read_zones(path: &str) ->  Result<UniquePtr<ApiZones>>;
index 80d1589e5116a1110db05200b1fa10a79bc4f7cd..b08b9ed019213d66b04efd75c57b1526d22a5e77 100644 (file)
@@ -210,13 +210,13 @@ impl AuthZone {
     }
 }
 
-pub fn validate_auth_zones(field: &str, vec: &Vec<AuthZone>) -> Result<(), ValidationError> {
+pub fn validate_auth_zones(field: &str, vec: &[AuthZone]) -> Result<(), ValidationError> {
     validate_vec(field, vec, |field, element| element.validate(field))
 }
 
 pub fn validate_forward_zones(
     field: &str,
-    vec: &Vec<ForwardZone>,
+    vec: &[ForwardZone],
 ) -> 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: &Vec<String>) -> Result<(), ValidationError> {
+pub fn validate_allow_from(field: &str, vec: &[String]) -> Result<(), ValidationError> {
     validate_vec(field, vec, validate_subnet)
 }
 
@@ -280,11 +280,11 @@ pub fn allow_for_to_yaml_string(vec: &Vec<String>) -> Result<String, serde_yaml:
     allow_from_to_yaml_string(vec)
 }
 
-pub fn validate_allow_for(field: &str, vec: &Vec<String>) -> Result<(), ValidationError> {
+pub fn validate_allow_for(field: &str, vec: &[String]) -> Result<(), ValidationError> {
     validate_vec(field, vec, validate_name)
 }
 
-pub fn validate_allow_notify_for(field: &str, vec: &Vec<String>) -> Result<(), ValidationError> {
+pub fn validate_allow_notify_for(field: &str, vec: &[String]) -> Result<(), ValidationError> {
     validate_vec(field, vec, validate_name)
 }
 
index 2737f78ec02d8bdfbb52680b558f89742c6685fe..5ec0c01c5715d10bdb20094e579d1c5c45951f93 100644 (file)
@@ -103,7 +103,7 @@ static void apiServerConfigACL(const std::string& aclType, HttpRequest* req, Htt
       }
 
       try {
-        ::pdns::rust::settings::rec::validate_allow_from(aclType, vec);
+        ::pdns::rust::settings::rec::validate_allow_from(aclType, {vec.data(), vec.size()});
       }
       catch (const ::rust::Error& e) {
         throw ApiException(string("Unable to convert: ") + e.what());