use std::ffi::c_void;
use crate::errors::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ConfigName {
StackSize,
MaxStringsPerRule,
MaxMatchData,
}
#[cfg(unix)]
type EnumType = u32;
#[cfg(windows)]
type EnumType = i32;
impl ConfigName {
pub fn to_yara(&self) -> EnumType {
use self::ConfigName::*;
let res = match self {
StackSize => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_STACK_SIZE,
MaxStringsPerRule => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_STRINGS_PER_RULE,
MaxMatchData => yara_sys::_YR_CONFIG_NAME_YR_CONFIG_MAX_MATCH_DATA,
};
res as EnumType
}
}
pub fn set_configuration(name: ConfigName, value: u32) -> Result<(), YaraError> {
let result = unsafe {
yara_sys::yr_set_configuration(name.to_yara(), &value as *const u32 as *mut c_void)
};
yara_sys::Error::from_code(result).map_err(Into::into)
}
pub fn get_configuration(name: ConfigName) -> Result<u32, YaraError> {
let value: u32 = 0;
let result = unsafe {
yara_sys::yr_get_configuration(name.to_yara(), &value as *const u32 as *mut c_void)
};
yara_sys::Error::from_code(result)
.map_err(Into::into)
.map(|_| value)
}