//! Module for retrieving configuration details.
-use std::os::raw::c_char;
-use std::os::raw::c_int;
-use std::ffi::{CString, CStr};
-use std::ptr;
-use std::str;
use nom7::{
character::complete::{multispace0, not_line_ending},
- sequence::{preceded, tuple},
- number::complete::double,
combinator::verify,
+ number::complete::double,
+ sequence::{preceded, tuple},
IResult,
};
+use std::ffi::{CStr, CString};
+use std::os::raw::c_char;
+use std::os::raw::c_int;
+use std::ptr;
+use std::str;
use suricata_sys::sys::SCConfGet;
use suricata_sys::sys::SCConfGetChildValue;
use suricata_sys::sys::SCConfGetChildValueBool;
return None;
}
- let value = str::from_utf8(unsafe{
- CStr::from_ptr(vptr).to_bytes()
- }).unwrap();
+ let value = str::from_utf8(unsafe { CStr::from_ptr(vptr).to_bytes() }).unwrap();
return Some(value);
}
}
impl ConfNode {
-
pub fn wrap(conf: *const SCConfNode) -> Self {
- return Self { conf }
+ return Self { conf };
}
pub fn get_child_value(&self, key: &str) -> Option<&str> {
unsafe {
let s = CString::new(key).unwrap();
- if SCConfGetChildValue(self.conf,
- s.as_ptr(),
- &mut vptr) != 1 {
+ if SCConfGetChildValue(self.conf, s.as_ptr(), &mut vptr) != 1 {
return None;
}
}
return None;
}
- let value = str::from_utf8(unsafe{
- CStr::from_ptr(vptr).to_bytes()
- }).unwrap();
+ let value = str::from_utf8(unsafe { CStr::from_ptr(vptr).to_bytes() }).unwrap();
return Some(value);
}
unsafe {
let s = CString::new(key).unwrap();
- if SCConfGetChildValueBool(self.conf,
- s.as_ptr(),
- &mut vptr) != 1 {
+ if SCConfGetChildValueBool(self.conf, s.as_ptr(), &mut vptr) != 1 {
return false;
}
}
}
return false;
}
-
}
-const BYTE: u64 = 1;
-const KILOBYTE: u64 = 1024;
-const MEGABYTE: u64 = 1_048_576;
-const GIGABYTE: u64 = 1_073_741_824;
+const BYTE: u64 = 1;
+const KILOBYTE: u64 = 1024;
+const MEGABYTE: u64 = 1_048_576;
+const GIGABYTE: u64 = 1_073_741_824;
/// Helper function to retrieve memory unit from a string slice
///
fn get_memunit(unit: &str) -> u64 {
let unit = &unit.to_lowercase()[..];
match unit {
- "b" => { BYTE }
- "kb" => { KILOBYTE }
- "mb" => { MEGABYTE }
- "gb" => { GIGABYTE }
- _ => { 0 }
+ "b" => BYTE,
+ "kb" => KILOBYTE,
+ "mb" => MEGABYTE,
+ "gb" => GIGABYTE,
+ _ => 0,
}
}
let arg = arg.trim();
let val: f64;
let mut unit: &str;
- let mut parser = tuple((preceded(multispace0, double),
- preceded(multispace0, verify(not_line_ending, |c: &str| c.len() < 3))));
+ let mut parser = tuple((
+ preceded(multispace0, double),
+ preceded(multispace0, verify(not_line_ending, |c: &str| c.len() < 3)),
+ ));
let r: IResult<&str, (f64, &str)> = parser(arg);
if let Ok(r) = r {
val = (r.1).0;
#[test]
fn test_memval_nospace() {
let s = "10";
- let res = 10 ;
+ let res = 10;
assert_eq!(Ok(10), get_memval(s));
let s = "10kb";
#[test]
fn test_memval_space_start() {
let s = " 10";
- let res = 10 ;
+ let res = 10;
assert_eq!(Ok(res), get_memval(s));
let s = " 10Kb";
#[test]
fn test_memval_space_end() {
let s = " 10 ";
- let res = 10 ;
+ let res = 10;
assert_eq!(Ok(res), get_memval(s));
let s = "10Kb ";
#[test]
fn test_memval_space_in_bw() {
let s = " 10 ";
- let res = 10 ;
+ let res = 10;
assert_eq!(Ok(res), get_memval(s));
let s = "10 Kb ";