From baa7021ee679e27082af614ddc9c72d1837f3f9e Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 16 Nov 2022 23:50:13 -0600 Subject: [PATCH] rust/conf: add fn conf_get_node A wrapper around ConfGetNode to get a configuration node by name. --- rust/src/conf.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rust/src/conf.rs b/rust/src/conf.rs index 0dae7a013a..6980cd0f29 100644 --- a/rust/src/conf.rs +++ b/rust/src/conf.rs @@ -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 { + 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.