]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/conf: add fn conf_get_node
authorJason Ish <jason.ish@oisf.net>
Thu, 17 Nov 2022 05:50:13 +0000 (23:50 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:09:10 +0000 (14:09 +0100)
A wrapper around ConfGetNode to get a configuration node by name.

rust/src/conf.rs

index 0dae7a013a64914a1ecb075c5dfe03378d18d599..6980cd0f297661ed668e668487a6b7129fa58755 100644 (file)
@@ -35,6 +35,22 @@ extern {
                          vptr: *mut *const c_char) -> i8;
     fn ConfGetChildValueBool(conf: *const c_void, key: *const c_char,
                              vptr: *mut c_int) -> i8;
+    fn ConfGetNode(key: *const c_char) -> *const c_void;
+}
+
+pub fn conf_get_node(key: &str) -> Option<ConfNode> {
+    let key = if let Ok(key) = CString::new(key) {
+        key
+    } else {
+        return None;
+    };
+
+    let node = unsafe { ConfGetNode(key.as_ptr()) };
+    if node.is_null() {
+        None
+    } else {
+        Some(ConfNode::wrap(node))
+    }
 }
 
 // Return the string value of a configuration value.