Move enabled/disabled functionality from analyzers into Component base class API.

The different analyzers types all had their own methods for
enabling/disabling their availability. This change abstracts that into
a new API inside their base class (`plugin::Component`) so that they
can be toggled in a unified way.

In principle, other types of components could/should use this as well
now, so that, e.g., an input reader's availability could be toggled at
runtime. The code doesn't make that broader change for now because it
would requires a series of changes wherever these other component
types are being used. However, that means that one now could try
toggling some other component through the new API without that having
any effect. To catch that, there's a runtime check in place that turns
any such attempt into an internal error.
This commit is contained in:
Robin Sommer 2024-04-30 08:16:01 +02:00
parent d7e30d9ee2
commit ac1a7508ee
No known key found for this signature in database
GPG key ID: D8187293B3FFE5D0
8 changed files with 50 additions and 55 deletions

View file

@ -11,7 +11,7 @@ namespace zeek::file_analysis {
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype, bool arg_enabled)
: plugin::Component(plugin::component::FILE_ANALYZER, name, subtype, file_mgr->GetTagType()) {
factory_func = arg_factory;
enabled = arg_enabled;
SetEnabled(arg_enabled);
}
void Component::Initialize() {
@ -26,7 +26,7 @@ void Component::DoDescribe(ODesc* d) const {
d->Add(", ");
}
d->Add(enabled ? "enabled" : "disabled");
d->Add(Enabled() ? "enabled" : "disabled");
}
} // namespace zeek::file_analysis

View file

@ -70,20 +70,6 @@ public:
*/
factory_function FactoryFunction() const { return factory_func; }
/**
* Returns true if the analyzer is currently enabled and hence
* available for use.
*/
bool Enabled() const { return enabled; }
/**
* Enables or disables this analyzer.
*
* @param arg_enabled True to enabled, false to disable.
*
*/
void SetEnabled(bool arg_enabled) { enabled = arg_enabled; }
protected:
/**
* Overridden from plugin::Component.
@ -94,7 +80,6 @@ private:
friend class Manager;
factory_function factory_func; // The analyzer's factory callback.
bool enabled; // True if the analyzer is enabled.
};
} // namespace file_analysis