conf: extend API for rust

Will allow rust to list the values of an array such as
dns.types for outputs
pull/12951/head
Philippe Antoine 1 year ago committed by Philippe Antoine
parent ef8b13c1ef
commit 30af626a92

@ -34,6 +34,10 @@ use suricata_sys::sys::SCConfGetChildValue;
use suricata_sys::sys::SCConfGetChildValueBool; use suricata_sys::sys::SCConfGetChildValueBool;
use suricata_sys::sys::SCConfGetNode; use suricata_sys::sys::SCConfGetNode;
use suricata_sys::sys::SCConfNode; use suricata_sys::sys::SCConfNode;
use suricata_sys::sys::SCConfNodeLookupChild;
use suricata_sys::sys::SCConfGetFirstNode;
use suricata_sys::sys::SCConfGetNextNode;
use suricata_sys::sys::SCConfGetValueNode;
pub fn conf_get_node(key: &str) -> Option<ConfNode> { pub fn conf_get_node(key: &str) -> Option<ConfNode> {
let key = if let Ok(key) = CString::new(key) { let key = if let Ok(key) = CString::new(key) {
@ -92,6 +96,42 @@ impl ConfNode {
return Self { conf }; return Self { conf };
} }
pub fn get_child_node(&self, key: &str) -> Option<ConfNode> {
let node = unsafe {
let s = CString::new(key).unwrap();
SCConfNodeLookupChild(self.conf, s.as_ptr())
};
if node.is_null() {
None
} else {
Some(ConfNode::wrap(node))
}
}
pub fn first(&self) -> Option<ConfNode> {
let node = unsafe { SCConfGetFirstNode(self.conf) };
if node.is_null() {
None
} else {
Some(ConfNode::wrap(node))
}
}
pub fn next(&self) -> Option<ConfNode> {
let node = unsafe { SCConfGetNextNode(self.conf) };
if node.is_null() {
None
} else {
Some(ConfNode::wrap(node))
}
}
pub fn value(&self) -> &str {
let vptr = unsafe { SCConfGetValueNode(self.conf) };
let value = std::str::from_utf8(unsafe { CStr::from_ptr(vptr).to_bytes() }).unwrap();
return value;
}
pub fn get_child_value(&self, key: &str) -> Option<&str> { pub fn get_child_value(&self, key: &str) -> Option<&str> {
let mut vptr: *const c_char = ptr::null_mut(); let mut vptr: *const c_char = ptr::null_mut();

@ -328,3 +328,12 @@ extern "C" {
parent: *mut SCConfNode, name: *const ::std::os::raw::c_char, final_: ::std::os::raw::c_int, parent: *mut SCConfNode, name: *const ::std::os::raw::c_char, final_: ::std::os::raw::c_int,
) -> *mut SCConfNode; ) -> *mut SCConfNode;
} }
extern "C" {
pub fn SCConfGetFirstNode(parent: *const SCConfNode) -> *mut SCConfNode;
}
extern "C" {
pub fn SCConfGetNextNode(node: *const SCConfNode) -> *mut SCConfNode;
}
extern "C" {
pub fn SCConfGetValueNode(node: *const SCConfNode) -> *const ::std::os::raw::c_char;
}

@ -201,6 +201,21 @@ SCConfNode *SCConfGetNode(const char *name)
return node; return node;
} }
SCConfNode *SCConfGetFirstNode(const SCConfNode *parent)
{
return TAILQ_FIRST(&parent->head);
}
SCConfNode *SCConfGetNextNode(const SCConfNode *node)
{
return TAILQ_NEXT(node, next);
}
const char *SCConfGetValueNode(const SCConfNode *node)
{
return node->val;
}
/** /**
* \brief Get the root configuration node. * \brief Get the root configuration node.
*/ */

@ -100,4 +100,9 @@ SCConfNode *SCConfSetIfaceNode(const char *ifaces_node_name, const char *iface);
int SCConfSetRootAndDefaultNodes(const char *ifaces_node_name, const char *iface, int SCConfSetRootAndDefaultNodes(const char *ifaces_node_name, const char *iface,
SCConfNode **if_root, SCConfNode **if_default); SCConfNode **if_root, SCConfNode **if_default);
SCConfNode *SCConfNodeGetNodeOrCreate(SCConfNode *parent, const char *name, int final); SCConfNode *SCConfNodeGetNodeOrCreate(SCConfNode *parent, const char *name, int final);
SCConfNode *SCConfGetFirstNode(const SCConfNode *parent);
SCConfNode *SCConfGetNextNode(const SCConfNode *node);
const char *SCConfGetValueNode(const SCConfNode *node);
#endif /* ! SURICATA_CONF_H */ #endif /* ! SURICATA_CONF_H */

Loading…
Cancel
Save