Skip to content

Commit

Permalink
refactor: rename add_unsupported_module to ignore_module.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Mar 19, 2024
1 parent 3d74a44 commit e344cd5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 38 deletions.
12 changes: 6 additions & 6 deletions capi/include/yara-x.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ enum YRX_RESULT yrx_compiler_add_source(struct YRX_COMPILER *compiler,

// Tell the compiler that a YARA module is not supported.
//
// Import statements for unsupported modules will be ignored without
// errors, but a warning will be used. Any rule that make use of an
// unsupported module will be ignored, while the rest of rules that
// don't rely on that module will be correctly compiled.
enum YRX_RESULT yrx_compiler_add_unsupported_module(struct YRX_COMPILER *compiler,
const char *module);
// Import statements for ignored modules will be ignored without errors but a
// warning will be issued. Any rule that make use of an ignored module will be
// ignored, while the rest of rules that don't rely on that module will be
// correctly compiled.
enum YRX_RESULT yrx_compiler_ignore_module(struct YRX_COMPILER *compiler,
const char *module);

// Creates a new namespace.
//
Expand Down
12 changes: 6 additions & 6 deletions capi/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ pub unsafe extern "C" fn yrx_compiler_add_source(

/// Tell the compiler that a YARA module is not supported.
///
/// Import statements for unsupported modules will be ignored without
/// errors, but a warning will be used. Any rule that make use of an
/// unsupported module will be ignored, while the rest of rules that
/// don't rely on that module will be correctly compiled.
/// Import statements for ignored modules will be ignored without errors but a
/// warning will be issued. Any rule that make use of an ignored module will be
/// ignored, while the rest of rules that don't rely on that module will be
/// correctly compiled.
#[no_mangle]
pub unsafe extern "C" fn yrx_compiler_add_unsupported_module(
pub unsafe extern "C" fn yrx_compiler_ignore_module(
compiler: *mut YRX_COMPILER,
module: *const c_char,
) -> YRX_RESULT {
Expand All @@ -75,7 +75,7 @@ pub unsafe extern "C" fn yrx_compiler_add_unsupported_module(
return YRX_RESULT::INVALID_ARGUMENT;
};

compiler.inner.add_unsupported_module(module);
compiler.inner.ignore_module(module);

YRX_RESULT::SUCCESS
}
Expand Down
2 changes: 1 addition & 1 deletion go/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Compiler) AddSource(src string) error {
func (c *Compiler) IgnoreModule(module string) {
cModule := C.CString(module)
defer C.free(unsafe.Pointer(cModule))
result := C.yrx_compiler_add_unsupported_module(c.cCompiler, cModule)
result := C.yrx_compiler_ignore_module(c.cCompiler, cModule)
if result != C.SUCCESS {
panic("yrx_compiler_add_unsupported_module failed")
}
Expand Down
26 changes: 11 additions & 15 deletions lib/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub struct Compiler<'a> {
/// without causing an error, but a warning is raised to let the user know
/// that the module is not supported. Any rule that depends on an unsupported
/// module is ignored.
unsupported_modules: Vec<String>,
ignored_modules: Vec<String>,

/// Keys in this map are the name of rules that will be ignored because they
/// depend on unsupported modules, either directly or indirectly. Values are
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a> Compiler<'a> {
atoms: Vec::new(),
re_code: Vec::new(),
imported_modules: Vec::new(),
unsupported_modules: Vec::new(),
ignored_modules: Vec::new(),
ignored_rules: FxHashMap::default(),
root_struct: Struct::new().make_root(),
report_builder: ReportBuilder::new(),
Expand Down Expand Up @@ -524,15 +524,12 @@ impl<'a> Compiler<'a> {

/// Tell the compiler that a YARA module is not supported.
///
/// Import statements for unsupported modules will be ignored without
/// errors, but a warning will be used. Any rule that make use of an
/// unsupported module will be ignored, while the rest of rules that
/// Import statements for ignored modules will be ignored without
/// errors, but a warning will be issued. Any rule that make use of an
/// ignored module will be ignored, while the rest of rules that
/// don't rely on that module will be correctly compiled.
pub fn add_unsupported_module<M: Into<String>>(
&mut self,
module: M,
) -> &mut Self {
self.unsupported_modules.push(module.into());
pub fn ignore_module<M: Into<String>>(&mut self, module: M) -> &mut Self {
self.ignored_modules.push(module.into());
self
}

Expand Down Expand Up @@ -725,7 +722,7 @@ impl<'a> Compiler<'a> {
Ok(condition) => condition,
Err(CompileError::UnknownIdentifier {
identifier, span, ..
}) if self.unsupported_modules.contains(&identifier)
}) if self.ignored_modules.contains(&identifier)
|| self.ignored_rules.contains_key(&identifier) =>
{
self.restore_snapshot(snapshot);
Expand All @@ -740,7 +737,7 @@ impl<'a> Compiler<'a> {
span,
));
} else {
self.warnings.push(Warning::unsupported_module(
self.warnings.push(Warning::ignored_module(
&self.report_builder,
identifier.clone(),
span,
Expand Down Expand Up @@ -884,9 +881,8 @@ impl<'a> Compiler<'a> {
// The module does not exist, but it is included in the list
// of unsupported modules. In such cases we don't raise an error,
// only a warning.
return if self.unsupported_modules.iter().any(|m| m == module_name)
{
self.warnings.push(Warning::unsupported_module(
return if self.ignored_modules.iter().any(|m| m == module_name) {
self.warnings.push(Warning::ignored_module(
&self.report_builder,
module_name.to_string(),
import.span(),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/compiler/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ fn unsupported_modules() {
let mut compiler = Compiler::new();

compiler
.add_unsupported_module("foo_module")
.ignore_module("foo_module")
.add_source(
r#"
import "foo_module"
Expand Down
5 changes: 1 addition & 4 deletions lib/src/compiler/tests/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,7 @@ rule test_2 {

for t in tests {
let mut compiler = Compiler::new();
compiler
.add_unsupported_module("unsupported_module")
.add_source(t.1)
.unwrap();
compiler.ignore_module("unsupported_module").add_source(t.1).unwrap();
assert!(
!compiler.warnings.is_empty(),
"test at line {} didn't produce warnings",
Expand Down
2 changes: 1 addition & 1 deletion parser/src/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub enum Warning {
#[warning("module `{module_name}` is not supported")]
#[label("module `{module_name}` used here", span)]
#[note(note)]
UnsupportedModule {
IgnoredModule {
detailed_report: String,
module_name: String,
span: Span,
Expand Down
8 changes: 4 additions & 4 deletions py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ impl Compiler {
/// Tell the compiler that a YARA module is not supported.
///
/// Import statements for unsupported modules will be ignored without
/// errors, but a warning will be used. Any rule that make use of an
/// unsupported module will be ignored, while the rest of rules that
/// errors, but a warning will be issued. Any rule that make use of an
/// ignored module will be ignored, while the rest of rules that
/// don't rely on that module will be correctly compiled.
fn add_unsupported_module(&mut self, module: &str) {
self.inner.add_unsupported_module(module);
fn ignore_module(&mut self, module: &str) {
self.inner.ignore_module(module);
}

/// Builds the source code previously added to the compiler.
Expand Down

0 comments on commit e344cd5

Please sign in to comment.