mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The one place where we deviate is header include order since Zeek depends on headers being included in a certain order.
This commit is contained in:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
|
@ -5,91 +5,66 @@
|
|||
#include "zeek/Desc.h"
|
||||
#include "zeek/Reporter.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
namespace zeek::plugin {
|
||||
|
||||
Tag::type_t Component::type_counter(0);
|
||||
|
||||
Component::Component(component::Type arg_type, const std::string& arg_name,
|
||||
Tag::subtype_t tag_subtype, EnumTypePtr etype)
|
||||
: type(arg_type), name(arg_name), tag(etype, 1, 0), etype(std::move(etype)),
|
||||
tag_subtype(tag_subtype)
|
||||
{
|
||||
canon_name = util::canonify_name(name);
|
||||
canon_name_val = make_intrusive<StringVal>(canon_name);
|
||||
}
|
||||
Component::Component(component::Type arg_type, const std::string& arg_name, Tag::subtype_t tag_subtype,
|
||||
EnumTypePtr etype)
|
||||
: type(arg_type), name(arg_name), tag(etype, 1, 0), etype(std::move(etype)), tag_subtype(tag_subtype) {
|
||||
canon_name = util::canonify_name(name);
|
||||
canon_name_val = make_intrusive<StringVal>(canon_name);
|
||||
}
|
||||
|
||||
void Component::Describe(ODesc* d) const
|
||||
{
|
||||
d->Add(" ");
|
||||
d->Add("[");
|
||||
void Component::Describe(ODesc* d) const {
|
||||
d->Add(" ");
|
||||
d->Add("[");
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case component::READER:
|
||||
d->Add("Reader");
|
||||
break;
|
||||
switch ( type ) {
|
||||
case component::READER: d->Add("Reader"); break;
|
||||
|
||||
case component::WRITER:
|
||||
d->Add("Writer");
|
||||
break;
|
||||
case component::WRITER: d->Add("Writer"); break;
|
||||
|
||||
case component::ANALYZER:
|
||||
d->Add("Analyzer");
|
||||
break;
|
||||
case component::ANALYZER: d->Add("Analyzer"); break;
|
||||
|
||||
case component::PACKET_ANALYZER:
|
||||
d->Add("Packet Analyzer");
|
||||
break;
|
||||
case component::PACKET_ANALYZER: d->Add("Packet Analyzer"); break;
|
||||
|
||||
case component::FILE_ANALYZER:
|
||||
d->Add("File Analyzer");
|
||||
break;
|
||||
case component::FILE_ANALYZER: d->Add("File Analyzer"); break;
|
||||
|
||||
case component::IOSOURCE:
|
||||
d->Add("I/O Source");
|
||||
break;
|
||||
case component::IOSOURCE: d->Add("I/O Source"); break;
|
||||
|
||||
case component::PKTSRC:
|
||||
d->Add("Packet Source");
|
||||
break;
|
||||
case component::PKTSRC: d->Add("Packet Source"); break;
|
||||
|
||||
case component::PKTDUMPER:
|
||||
d->Add("Packet Dumper");
|
||||
break;
|
||||
case component::PKTDUMPER: d->Add("Packet Dumper"); break;
|
||||
|
||||
case component::SESSION_ADAPTER:
|
||||
d->Add("Session Adapter");
|
||||
break;
|
||||
case component::SESSION_ADAPTER: d->Add("Session Adapter"); break;
|
||||
|
||||
default:
|
||||
reporter->InternalWarning("unknown component type in plugin::Component::Describe");
|
||||
d->Add("<unknown component type>");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
reporter->InternalWarning("unknown component type in plugin::Component::Describe");
|
||||
d->Add("<unknown component type>");
|
||||
break;
|
||||
}
|
||||
|
||||
d->Add("]");
|
||||
d->Add(" ");
|
||||
d->Add(name);
|
||||
d->Add(" (");
|
||||
DoDescribe(d);
|
||||
d->Add(")");
|
||||
}
|
||||
d->Add("]");
|
||||
d->Add(" ");
|
||||
d->Add(name);
|
||||
d->Add(" (");
|
||||
DoDescribe(d);
|
||||
d->Add(")");
|
||||
}
|
||||
|
||||
void Component::InitializeTag()
|
||||
{
|
||||
assert(tag_initialized == false);
|
||||
tag_initialized = true;
|
||||
tag = zeek::Tag(etype, ++type_counter, tag_subtype);
|
||||
}
|
||||
void Component::InitializeTag() {
|
||||
assert(tag_initialized == false);
|
||||
tag_initialized = true;
|
||||
tag = zeek::Tag(etype, ++type_counter, tag_subtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The component's tag.
|
||||
*/
|
||||
zeek::Tag Component::Tag() const
|
||||
{
|
||||
assert(tag_initialized);
|
||||
return tag;
|
||||
}
|
||||
zeek::Tag Component::Tag() const {
|
||||
assert(tag_initialized);
|
||||
return tag;
|
||||
}
|
||||
|
||||
} // namespace zeek::plugin
|
||||
} // namespace zeek::plugin
|
||||
|
|
|
@ -10,144 +10,139 @@
|
|||
#include "zeek/Type.h"
|
||||
#include "zeek/Val.h"
|
||||
|
||||
namespace zeek
|
||||
{
|
||||
namespace zeek {
|
||||
|
||||
class ODesc;
|
||||
|
||||
namespace plugin
|
||||
{
|
||||
namespace component
|
||||
{
|
||||
namespace plugin {
|
||||
namespace component {
|
||||
|
||||
/**
|
||||
* Component types.
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
READER, /// An input reader (not currently used).
|
||||
WRITER, /// A logging writer (not currently used).
|
||||
ANALYZER, /// A protocol analyzer.
|
||||
PACKET_ANALYZER, /// A packet analyzer.
|
||||
FILE_ANALYZER, /// A file analyzer.
|
||||
IOSOURCE, /// An I/O source, excluding packet sources.
|
||||
PKTSRC, /// A packet source.
|
||||
PKTDUMPER, /// A packet dumper.
|
||||
SESSION_ADAPTER, /// A session adapter analyzer.
|
||||
};
|
||||
enum Type {
|
||||
READER, /// An input reader (not currently used).
|
||||
WRITER, /// A logging writer (not currently used).
|
||||
ANALYZER, /// A protocol analyzer.
|
||||
PACKET_ANALYZER, /// A packet analyzer.
|
||||
FILE_ANALYZER, /// A file analyzer.
|
||||
IOSOURCE, /// An I/O source, excluding packet sources.
|
||||
PKTSRC, /// A packet source.
|
||||
PKTDUMPER, /// A packet dumper.
|
||||
SESSION_ADAPTER, /// A session adapter analyzer.
|
||||
};
|
||||
|
||||
} // namespace component
|
||||
} // namespace component
|
||||
|
||||
/**
|
||||
* Base class for plugin components. A component is a specific piece of
|
||||
* functionality that a plugin provides, such as a protocol analyzer or a log
|
||||
* writer.
|
||||
*/
|
||||
class Component
|
||||
{
|
||||
class Component {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The type of the component.
|
||||
*
|
||||
* @param name A descriptive name for the component. This name must
|
||||
* be unique across all components of the same type.
|
||||
*
|
||||
* @param tag_subtype A subtype associated with this component that
|
||||
* further distinguishes it. The subtype will be integrated into
|
||||
* the Tag that the manager associates with this component,
|
||||
* and component instances can accordingly access it via Tag().
|
||||
* If not used, leave at zero.
|
||||
*
|
||||
* @param etype An enum type that describes the type for the tag in
|
||||
* script-land.
|
||||
*/
|
||||
Component(component::Type type, const std::string& name, Tag::subtype_t tag_subtype = 0,
|
||||
EnumTypePtr etype = nullptr);
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param type The type of the component.
|
||||
*
|
||||
* @param name A descriptive name for the component. This name must
|
||||
* be unique across all components of the same type.
|
||||
*
|
||||
* @param tag_subtype A subtype associated with this component that
|
||||
* further distinguishes it. The subtype will be integrated into
|
||||
* the Tag that the manager associates with this component,
|
||||
* and component instances can accordingly access it via Tag().
|
||||
* If not used, leave at zero.
|
||||
*
|
||||
* @param etype An enum type that describes the type for the tag in
|
||||
* script-land.
|
||||
*/
|
||||
Component(component::Type type, const std::string& name, Tag::subtype_t tag_subtype = 0,
|
||||
EnumTypePtr etype = nullptr);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Component() = default;
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Component() = default;
|
||||
|
||||
// Disable.
|
||||
Component(const Component& other) = delete;
|
||||
Component operator=(const Component& other) = delete;
|
||||
// Disable.
|
||||
Component(const Component& other) = delete;
|
||||
Component operator=(const Component& other) = delete;
|
||||
|
||||
/**
|
||||
* Initialization function. This function has to be called before any
|
||||
* plugin component functionality is used; it commonly is used to add the
|
||||
* plugin component to the list of components and to initialize tags
|
||||
*/
|
||||
virtual void Initialize() { }
|
||||
/**
|
||||
* Initialization function. This function has to be called before any
|
||||
* plugin component functionality is used; it commonly is used to add the
|
||||
* plugin component to the list of components and to initialize tags
|
||||
*/
|
||||
virtual void Initialize() {}
|
||||
|
||||
/**
|
||||
* Returns the component's type.
|
||||
*/
|
||||
component::Type Type() const { return type; }
|
||||
/**
|
||||
* Returns the component's type.
|
||||
*/
|
||||
component::Type Type() const { return type; }
|
||||
|
||||
/**
|
||||
* Returns the component's name.
|
||||
*/
|
||||
const std::string& Name() const { return name; }
|
||||
/**
|
||||
* Returns the component's name.
|
||||
*/
|
||||
const std::string& Name() const { return name; }
|
||||
|
||||
/**
|
||||
* Returns a canonicalized version of the components's name. The
|
||||
* returned name is derived from what's passed to the constructor but
|
||||
* upper-cased and transformed to allow being part of a script-level
|
||||
* ID.
|
||||
*/
|
||||
const std::string& CanonicalName() const { return canon_name; }
|
||||
StringValPtr CanonicalNameVal() const { return canon_name_val; }
|
||||
/**
|
||||
* Returns a canonicalized version of the components's name. The
|
||||
* returned name is derived from what's passed to the constructor but
|
||||
* upper-cased and transformed to allow being part of a script-level
|
||||
* ID.
|
||||
*/
|
||||
const std::string& CanonicalName() const { return canon_name; }
|
||||
StringValPtr CanonicalNameVal() const { return canon_name_val; }
|
||||
|
||||
/**
|
||||
* Returns a textual representation of the component. This goes into
|
||||
* the output of "zeek -NN".
|
||||
*
|
||||
* By default, this just outputs the type and the name. Derived
|
||||
* versions can override DoDescribe() to add type specific details.
|
||||
*
|
||||
* @param d The description object to use.
|
||||
*/
|
||||
void Describe(ODesc* d) const;
|
||||
/**
|
||||
* Returns a textual representation of the component. This goes into
|
||||
* the output of "zeek -NN".
|
||||
*
|
||||
* By default, this just outputs the type and the name. Derived
|
||||
* versions can override DoDescribe() to add type specific details.
|
||||
*
|
||||
* @param d The description object to use.
|
||||
*/
|
||||
void Describe(ODesc* d) const;
|
||||
|
||||
/**
|
||||
* Initializes tag by creating the unique tag value for this component.
|
||||
* Has to be called exactly once.
|
||||
*/
|
||||
void InitializeTag();
|
||||
/**
|
||||
* Initializes tag by creating the unique tag value for this component.
|
||||
* Has to be called exactly once.
|
||||
*/
|
||||
void InitializeTag();
|
||||
|
||||
/**
|
||||
* @return The component's tag.
|
||||
*/
|
||||
zeek::Tag Tag() const;
|
||||
/**
|
||||
* @return The component's tag.
|
||||
*/
|
||||
zeek::Tag Tag() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Adds type specific information to the output of Describe().
|
||||
*
|
||||
* The default version does nothing.
|
||||
*
|
||||
* @param d The description object to use.
|
||||
*/
|
||||
virtual void DoDescribe(ODesc* d) const { }
|
||||
/**
|
||||
* Adds type specific information to the output of Describe().
|
||||
*
|
||||
* The default version does nothing.
|
||||
*
|
||||
* @param d The description object to use.
|
||||
*/
|
||||
virtual void DoDescribe(ODesc* d) const {}
|
||||
|
||||
private:
|
||||
component::Type type;
|
||||
std::string name;
|
||||
std::string canon_name;
|
||||
StringValPtr canon_name_val;
|
||||
component::Type type;
|
||||
std::string name;
|
||||
std::string canon_name;
|
||||
StringValPtr canon_name_val;
|
||||
|
||||
/** The automatically assigned component tag */
|
||||
zeek::Tag tag;
|
||||
EnumTypePtr etype;
|
||||
Tag::subtype_t tag_subtype;
|
||||
bool tag_initialized = false;
|
||||
/** The automatically assigned component tag */
|
||||
zeek::Tag tag;
|
||||
EnumTypePtr etype;
|
||||
Tag::subtype_t tag_subtype;
|
||||
bool tag_initialized = false;
|
||||
|
||||
/** Used to generate globally unique tags */
|
||||
static Tag::type_t type_counter;
|
||||
};
|
||||
/** Used to generate globally unique tags */
|
||||
static Tag::type_t type_counter;
|
||||
};
|
||||
|
||||
} // namespace plugin
|
||||
} // namespace zeek
|
||||
} // namespace plugin
|
||||
} // namespace zeek
|
||||
|
|
|
@ -17,8 +17,7 @@
|
|||
#include "zeek/module_util.h"
|
||||
#include "zeek/zeekygen/Manager.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
namespace zeek::plugin {
|
||||
|
||||
/**
|
||||
* A class that manages tracking of plugin components (e.g. analyzers) and
|
||||
|
@ -27,299 +26,286 @@ namespace zeek::plugin
|
|||
*
|
||||
* @tparam C A plugin::Component type derivative.
|
||||
*/
|
||||
template <class C> class ComponentManager
|
||||
{
|
||||
template<class C>
|
||||
class ComponentManager {
|
||||
public:
|
||||
/**
|
||||
* Constructor creates a new enum type to associate with
|
||||
* a component.
|
||||
*
|
||||
* @param module The script-layer module in which to install the ID
|
||||
* representing an enum type.
|
||||
*
|
||||
* @param local_id The local part of the ID of the new enum type
|
||||
* (e.g., "Tag").
|
||||
*/
|
||||
ComponentManager(const std::string& module, const std::string& local_id,
|
||||
const std::string& parent_module = "");
|
||||
/**
|
||||
* Constructor creates a new enum type to associate with
|
||||
* a component.
|
||||
*
|
||||
* @param module The script-layer module in which to install the ID
|
||||
* representing an enum type.
|
||||
*
|
||||
* @param local_id The local part of the ID of the new enum type
|
||||
* (e.g., "Tag").
|
||||
*/
|
||||
ComponentManager(const std::string& module, const std::string& local_id, const std::string& parent_module = "");
|
||||
|
||||
/**
|
||||
* @return The script-layer module in which the component's "Tag" ID lives.
|
||||
*/
|
||||
const std::string& GetModule() const;
|
||||
/**
|
||||
* @return The script-layer module in which the component's "Tag" ID lives.
|
||||
*/
|
||||
const std::string& GetModule() const;
|
||||
|
||||
/**
|
||||
* @return A list of all registered components.
|
||||
*/
|
||||
std::list<C*> GetComponents() const;
|
||||
/**
|
||||
* @return A list of all registered components.
|
||||
*/
|
||||
std::list<C*> GetComponents() const;
|
||||
|
||||
/**
|
||||
* @return The enum type associated with the script-layer "Tag".
|
||||
*/
|
||||
const EnumTypePtr& GetTagType() const;
|
||||
/**
|
||||
* @return The enum type associated with the script-layer "Tag".
|
||||
*/
|
||||
const EnumTypePtr& GetTagType() const;
|
||||
|
||||
/**
|
||||
* Get a component name from its tag.
|
||||
*
|
||||
* @param tag A component's tag.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(zeek::Tag tag) const;
|
||||
/**
|
||||
* Get a component name from its tag.
|
||||
*
|
||||
* @param tag A component's tag.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(zeek::Tag tag) const;
|
||||
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
*
|
||||
* @param val A component's enum value.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(EnumValPtr val) const;
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
*
|
||||
* @param val A component's enum value.
|
||||
* @return The canonical component name.
|
||||
*/
|
||||
const std::string& GetComponentName(EnumValPtr val) const;
|
||||
|
||||
/**
|
||||
* Get a component name from its tag.
|
||||
*
|
||||
* @param tag A component's tag.
|
||||
* @return The canonical component name as a StringValPtr.
|
||||
*/
|
||||
StringValPtr GetComponentNameVal(zeek::Tag tag) const;
|
||||
/**
|
||||
* Get a component name from its tag.
|
||||
*
|
||||
* @param tag A component's tag.
|
||||
* @return The canonical component name as a StringValPtr.
|
||||
*/
|
||||
StringValPtr GetComponentNameVal(zeek::Tag tag) const;
|
||||
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
*
|
||||
* @param val A component's enum value.
|
||||
* @return The canonical component name as a StringValPtr.
|
||||
*/
|
||||
StringValPtr GetComponentNameVal(EnumValPtr val) const;
|
||||
/**
|
||||
* Get a component name from it's enum value.
|
||||
*
|
||||
* @param val A component's enum value.
|
||||
* @return The canonical component name as a StringValPtr.
|
||||
*/
|
||||
StringValPtr GetComponentNameVal(EnumValPtr val) const;
|
||||
|
||||
/**
|
||||
* Get a component tag from its name.
|
||||
*
|
||||
* @param name A component's canonical name.
|
||||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component associated with the name exists.
|
||||
*/
|
||||
zeek::Tag GetComponentTag(const std::string& name) const;
|
||||
/**
|
||||
* Get a component tag from its name.
|
||||
*
|
||||
* @param name A component's canonical name.
|
||||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component associated with the name exists.
|
||||
*/
|
||||
zeek::Tag GetComponentTag(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Get a component tag from its enum value.
|
||||
*
|
||||
* @param v A component's enum value.
|
||||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component associated with the value exists.
|
||||
*/
|
||||
zeek::Tag GetComponentTag(Val* v) const;
|
||||
/**
|
||||
* Get a component tag from its enum value.
|
||||
*
|
||||
* @param v A component's enum value.
|
||||
* @return The component's tag, or a tag representing an error if
|
||||
* no such component associated with the value exists.
|
||||
*/
|
||||
zeek::Tag GetComponentTag(Val* v) const;
|
||||
|
||||
/**
|
||||
* Add a component the internal maps used to keep track of it and create
|
||||
* a script-layer ID for the component's enum value.
|
||||
*
|
||||
* @param component A component to track.
|
||||
* @param prefix The script-layer ID associated with the component's enum
|
||||
* value will be a concatenation of this prefix and the component's
|
||||
* canonical name.
|
||||
*/
|
||||
void RegisterComponent(C* component, const std::string& prefix = "");
|
||||
/**
|
||||
* Add a component the internal maps used to keep track of it and create
|
||||
* a script-layer ID for the component's enum value.
|
||||
*
|
||||
* @param component A component to track.
|
||||
* @param prefix The script-layer ID associated with the component's enum
|
||||
* value will be a concatenation of this prefix and the component's
|
||||
* canonical name.
|
||||
*/
|
||||
void RegisterComponent(C* component, const std::string& prefix = "");
|
||||
|
||||
/**
|
||||
* @param name The canonical name of a component.
|
||||
* @return The component associated with the name or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const std::string& name) const;
|
||||
/**
|
||||
* @param name The canonical name of a component.
|
||||
* @return The component associated with the name or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* @param name A component tag.
|
||||
* @return The component associated with the tag or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const zeek::Tag& tag) const;
|
||||
/**
|
||||
* @param name A component tag.
|
||||
* @return The component associated with the tag or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(const zeek::Tag& tag) const;
|
||||
|
||||
/**
|
||||
* @param name A component's enum value.
|
||||
* @return The component associated with the value or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(EnumVal* val) const;
|
||||
/**
|
||||
* @param name A component's enum value.
|
||||
* @return The component associated with the value or a null pointer if no
|
||||
* such component exists.
|
||||
*/
|
||||
C* Lookup(EnumVal* val) const;
|
||||
|
||||
private:
|
||||
/** Script layer module in which component tags live. */
|
||||
std::string module;
|
||||
std::string parent_module;
|
||||
/** Script layer module in which component tags live. */
|
||||
std::string module;
|
||||
std::string parent_module;
|
||||
|
||||
/** Module-local type of component tags. */
|
||||
EnumTypePtr tag_enum_type;
|
||||
EnumTypePtr parent_tag_enum_type;
|
||||
/** Module-local type of component tags. */
|
||||
EnumTypePtr tag_enum_type;
|
||||
EnumTypePtr parent_tag_enum_type;
|
||||
|
||||
std::map<std::string, C*> components_by_name;
|
||||
std::map<zeek::Tag, C*> components_by_tag;
|
||||
std::map<zeek_int_t, C*> components_by_val;
|
||||
};
|
||||
std::map<std::string, C*> components_by_name;
|
||||
std::map<zeek::Tag, C*> components_by_tag;
|
||||
std::map<zeek_int_t, C*> components_by_val;
|
||||
};
|
||||
|
||||
template <class C>
|
||||
template<class C>
|
||||
ComponentManager<C>::ComponentManager(const std::string& module, const std::string& local_id,
|
||||
const std::string& parent_module)
|
||||
: module(module), parent_module(parent_module)
|
||||
{
|
||||
tag_enum_type = make_intrusive<EnumType>(module + "::" + local_id);
|
||||
auto id = zeek::detail::install_ID(local_id.c_str(), module.c_str(), true, true);
|
||||
zeek::detail::add_type(id.get(), tag_enum_type, nullptr);
|
||||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
: module(module), parent_module(parent_module) {
|
||||
tag_enum_type = make_intrusive<EnumType>(module + "::" + local_id);
|
||||
auto id = zeek::detail::install_ID(local_id.c_str(), module.c_str(), true, true);
|
||||
zeek::detail::add_type(id.get(), tag_enum_type, nullptr);
|
||||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
|
||||
if ( ! parent_module.empty() )
|
||||
{
|
||||
// check to see if the parent module's type has been created already
|
||||
id = zeek::detail::lookup_ID(local_id.c_str(), parent_module.c_str(), false, true, false);
|
||||
if ( id != zeek::detail::ID::nil )
|
||||
{
|
||||
parent_tag_enum_type = id->GetType<EnumType>();
|
||||
}
|
||||
else
|
||||
{
|
||||
parent_tag_enum_type = make_intrusive<EnumType>(parent_module + "::" + local_id);
|
||||
id = zeek::detail::install_ID(local_id.c_str(), parent_module.c_str(), true, true);
|
||||
zeek::detail::add_type(id.get(), parent_tag_enum_type, nullptr);
|
||||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ! parent_module.empty() ) {
|
||||
// check to see if the parent module's type has been created already
|
||||
id = zeek::detail::lookup_ID(local_id.c_str(), parent_module.c_str(), false, true, false);
|
||||
if ( id != zeek::detail::ID::nil ) {
|
||||
parent_tag_enum_type = id->GetType<EnumType>();
|
||||
}
|
||||
else {
|
||||
parent_tag_enum_type = make_intrusive<EnumType>(parent_module + "::" + local_id);
|
||||
id = zeek::detail::install_ID(local_id.c_str(), parent_module.c_str(), true, true);
|
||||
zeek::detail::add_type(id.get(), parent_tag_enum_type, nullptr);
|
||||
zeek::detail::zeekygen_mgr->Identifier(std::move(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class C> const std::string& ComponentManager<C>::GetModule() const
|
||||
{
|
||||
return module;
|
||||
}
|
||||
template<class C>
|
||||
const std::string& ComponentManager<C>::GetModule() const {
|
||||
return module;
|
||||
}
|
||||
|
||||
template <class C> std::list<C*> ComponentManager<C>::GetComponents() const
|
||||
{
|
||||
std::list<C*> rval;
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i;
|
||||
template<class C>
|
||||
std::list<C*> ComponentManager<C>::GetComponents() const {
|
||||
std::list<C*> rval;
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i;
|
||||
|
||||
for ( i = components_by_tag.begin(); i != components_by_tag.end(); ++i )
|
||||
rval.push_back(i->second);
|
||||
for ( i = components_by_tag.begin(); i != components_by_tag.end(); ++i )
|
||||
rval.push_back(i->second);
|
||||
|
||||
return rval;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
template <class C> const EnumTypePtr& ComponentManager<C>::GetTagType() const
|
||||
{
|
||||
return tag_enum_type;
|
||||
}
|
||||
template<class C>
|
||||
const EnumTypePtr& ComponentManager<C>::GetTagType() const {
|
||||
return tag_enum_type;
|
||||
}
|
||||
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(zeek::Tag tag) const
|
||||
{
|
||||
static const std::string error = "<error>";
|
||||
template<class C>
|
||||
const std::string& ComponentManager<C>::GetComponentName(zeek::Tag tag) const {
|
||||
static const std::string error = "<error>";
|
||||
|
||||
if ( ! tag )
|
||||
return error;
|
||||
if ( ! tag )
|
||||
return error;
|
||||
|
||||
if ( C* c = Lookup(tag) )
|
||||
return c->CanonicalName();
|
||||
if ( C* c = Lookup(tag) )
|
||||
return c->CanonicalName();
|
||||
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str());
|
||||
return error;
|
||||
}
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str());
|
||||
return error;
|
||||
}
|
||||
|
||||
template <class C> const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const
|
||||
{
|
||||
static const std::string error = "<error>";
|
||||
template<class C>
|
||||
const std::string& ComponentManager<C>::GetComponentName(EnumValPtr val) const {
|
||||
static const std::string error = "<error>";
|
||||
|
||||
if ( ! val )
|
||||
return error;
|
||||
if ( ! val )
|
||||
return error;
|
||||
|
||||
if ( C* c = Lookup(val.get()) )
|
||||
return c->CanonicalName();
|
||||
if ( C* c = Lookup(val.get()) )
|
||||
return c->CanonicalName();
|
||||
|
||||
reporter->InternalWarning("requested name of unknown component tag %s",
|
||||
val->AsString()->CheckString());
|
||||
return error;
|
||||
}
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", val->AsString()->CheckString());
|
||||
return error;
|
||||
}
|
||||
|
||||
template <class C> StringValPtr ComponentManager<C>::GetComponentNameVal(zeek::Tag tag) const
|
||||
{
|
||||
static auto error = make_intrusive<StringVal>("<error>");
|
||||
template<class C>
|
||||
StringValPtr ComponentManager<C>::GetComponentNameVal(zeek::Tag tag) const {
|
||||
static auto error = make_intrusive<StringVal>("<error>");
|
||||
|
||||
if ( ! tag )
|
||||
return error;
|
||||
if ( ! tag )
|
||||
return error;
|
||||
|
||||
if ( C* c = Lookup(tag) )
|
||||
return c->CanonicalNameVal();
|
||||
if ( C* c = Lookup(tag) )
|
||||
return c->CanonicalNameVal();
|
||||
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str());
|
||||
return error;
|
||||
}
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str());
|
||||
return error;
|
||||
}
|
||||
|
||||
template <class C> StringValPtr ComponentManager<C>::GetComponentNameVal(EnumValPtr val) const
|
||||
{
|
||||
static auto error = make_intrusive<StringVal>("<error>");
|
||||
template<class C>
|
||||
StringValPtr ComponentManager<C>::GetComponentNameVal(EnumValPtr val) const {
|
||||
static auto error = make_intrusive<StringVal>("<error>");
|
||||
|
||||
if ( ! val )
|
||||
return error;
|
||||
if ( ! val )
|
||||
return error;
|
||||
|
||||
if ( C* c = Lookup(val.get()) )
|
||||
return c->CanonicalNameVal();
|
||||
if ( C* c = Lookup(val.get()) )
|
||||
return c->CanonicalNameVal();
|
||||
|
||||
reporter->InternalWarning("requested name of unknown component tag %s",
|
||||
val->AsString()->CheckString());
|
||||
return error;
|
||||
}
|
||||
reporter->InternalWarning("requested name of unknown component tag %s", val->AsString()->CheckString());
|
||||
return error;
|
||||
}
|
||||
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const
|
||||
{
|
||||
C* c = Lookup(name);
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
template<class C>
|
||||
zeek::Tag ComponentManager<C>::GetComponentTag(const std::string& name) const {
|
||||
C* c = Lookup(name);
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class C> zeek::Tag ComponentManager<C>::GetComponentTag(Val* v) const
|
||||
{
|
||||
C* c = Lookup(v->AsEnumVal());
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
template<class C>
|
||||
zeek::Tag ComponentManager<C>::GetComponentTag(Val* v) const {
|
||||
C* c = Lookup(v->AsEnumVal());
|
||||
return c ? c->Tag() : zeek::Tag();
|
||||
}
|
||||
|
||||
template <class C> C* ComponentManager<C>::Lookup(const std::string& name) const
|
||||
{
|
||||
typename std::map<std::string, C*>::const_iterator i = components_by_name.find(
|
||||
util::to_upper(name));
|
||||
return i != components_by_name.end() ? i->second : nullptr;
|
||||
}
|
||||
template<class C>
|
||||
C* ComponentManager<C>::Lookup(const std::string& name) const {
|
||||
typename std::map<std::string, C*>::const_iterator i = components_by_name.find(util::to_upper(name));
|
||||
return i != components_by_name.end() ? i->second : nullptr;
|
||||
}
|
||||
|
||||
template <class C> C* ComponentManager<C>::Lookup(const zeek::Tag& tag) const
|
||||
{
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
return i != components_by_tag.end() ? i->second : nullptr;
|
||||
}
|
||||
template<class C>
|
||||
C* ComponentManager<C>::Lookup(const zeek::Tag& tag) const {
|
||||
typename std::map<zeek::Tag, C*>::const_iterator i = components_by_tag.find(tag);
|
||||
return i != components_by_tag.end() ? i->second : nullptr;
|
||||
}
|
||||
|
||||
template <class C> C* ComponentManager<C>::Lookup(EnumVal* val) const
|
||||
{
|
||||
typename std::map<zeek_int_t, C*>::const_iterator i = components_by_val.find(
|
||||
val->InternalInt());
|
||||
return i != components_by_val.end() ? i->second : nullptr;
|
||||
}
|
||||
template<class C>
|
||||
C* ComponentManager<C>::Lookup(EnumVal* val) const {
|
||||
typename std::map<zeek_int_t, C*>::const_iterator i = components_by_val.find(val->InternalInt());
|
||||
return i != components_by_val.end() ? i->second : nullptr;
|
||||
}
|
||||
|
||||
template <class C>
|
||||
void ComponentManager<C>::RegisterComponent(C* component, const std::string& prefix)
|
||||
{
|
||||
std::string cname = component->CanonicalName();
|
||||
template<class C>
|
||||
void ComponentManager<C>::RegisterComponent(C* component, const std::string& prefix) {
|
||||
std::string cname = component->CanonicalName();
|
||||
|
||||
if ( Lookup(cname) )
|
||||
reporter->FatalError("Component '%s::%s' defined more than once", module.c_str(),
|
||||
cname.c_str());
|
||||
if ( Lookup(cname) )
|
||||
reporter->FatalError("Component '%s::%s' defined more than once", module.c_str(), cname.c_str());
|
||||
|
||||
DBG_LOG(DBG_PLUGINS, "Registering component %s (tag %s)", component->Name().c_str(),
|
||||
component->Tag().AsString().c_str());
|
||||
DBG_LOG(DBG_PLUGINS, "Registering component %s (tag %s)", component->Name().c_str(),
|
||||
component->Tag().AsString().c_str());
|
||||
|
||||
components_by_name.insert(std::make_pair(cname, component));
|
||||
components_by_tag.insert(std::make_pair(component->Tag(), component));
|
||||
components_by_val.insert(std::make_pair(component->Tag().AsVal()->InternalInt(), component));
|
||||
components_by_name.insert(std::make_pair(cname, component));
|
||||
components_by_tag.insert(std::make_pair(component->Tag(), component));
|
||||
components_by_val.insert(std::make_pair(component->Tag().AsVal()->InternalInt(), component));
|
||||
|
||||
// Install an identifier for enum value
|
||||
std::string id = util::fmt("%s%s", prefix.c_str(), cname.c_str());
|
||||
tag_enum_type->AddName(module, id.c_str(), component->Tag().AsVal()->InternalInt(), true,
|
||||
nullptr);
|
||||
// Install an identifier for enum value
|
||||
std::string id = util::fmt("%s%s", prefix.c_str(), cname.c_str());
|
||||
tag_enum_type->AddName(module, id.c_str(), component->Tag().AsVal()->InternalInt(), true, nullptr);
|
||||
|
||||
if ( parent_tag_enum_type )
|
||||
{
|
||||
std::string parent_id = util::fmt("%s_%s", util::strtoupper(module).c_str(), id.c_str());
|
||||
parent_tag_enum_type->AddName(parent_module, parent_id.c_str(),
|
||||
component->Tag().AsVal()->InternalInt(), true, nullptr);
|
||||
}
|
||||
}
|
||||
if ( parent_tag_enum_type ) {
|
||||
std::string parent_id = util::fmt("%s_%s", util::strtoupper(module).c_str(), id.c_str());
|
||||
parent_tag_enum_type->AddName(parent_module, parent_id.c_str(), component->Tag().AsVal()->InternalInt(), true,
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace zeek::plugin
|
||||
} // namespace zeek::plugin
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,10 +12,8 @@
|
|||
#include "zeek/plugin/Component.h"
|
||||
#include "zeek/plugin/Plugin.h"
|
||||
|
||||
namespace zeek
|
||||
{
|
||||
namespace plugin
|
||||
{
|
||||
namespace zeek {
|
||||
namespace plugin {
|
||||
|
||||
// Macros that trigger plugin hooks. We put this into macros to short-cut the
|
||||
// code for the most common case that no plugin defines the hook.
|
||||
|
@ -27,11 +25,11 @@ namespace plugin
|
|||
*
|
||||
* @param method_call The \a Manager method corresponding to the hook.
|
||||
*/
|
||||
#define PLUGIN_HOOK_VOID(hook, method_call) \
|
||||
{ \
|
||||
if ( zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) \
|
||||
zeek::plugin_mgr->method_call; \
|
||||
}
|
||||
#define PLUGIN_HOOK_VOID(hook, method_call) \
|
||||
{ \
|
||||
if ( zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) \
|
||||
zeek::plugin_mgr->method_call; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Macro to trigger hooks that return a result.
|
||||
|
@ -43,515 +41,499 @@ namespace plugin
|
|||
* @param default_result: The result to use if there's no plugin implementing
|
||||
* the hook.
|
||||
*/
|
||||
#define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \
|
||||
(zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? zeek::plugin_mgr->method_call \
|
||||
: (default_result))
|
||||
#define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \
|
||||
(zeek::plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? zeek::plugin_mgr->method_call : (default_result))
|
||||
|
||||
/**
|
||||
* A singleton object managing all plugins.
|
||||
*/
|
||||
class Manager
|
||||
{
|
||||
class Manager {
|
||||
public:
|
||||
using bif_init_func = void (*)(Plugin*);
|
||||
using plugin_list = std::list<Plugin*>;
|
||||
using component_list = Plugin::component_list;
|
||||
using inactive_plugin_list = std::list<std::pair<std::string, std::string>>;
|
||||
using bif_init_func = void (*)(Plugin*);
|
||||
using plugin_list = std::list<Plugin*>;
|
||||
using component_list = Plugin::component_list;
|
||||
using inactive_plugin_list = std::list<std::pair<std::string, std::string>>;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Manager();
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Manager();
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Manager();
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~Manager();
|
||||
|
||||
/**
|
||||
* Searches a set of directories for plugins. If a specified directory
|
||||
* does not contain a plugin itself, the method searches for plugins
|
||||
* recursively. For plugins found, the method makes them available for
|
||||
* later activation via ActivatePlugin().
|
||||
*
|
||||
* This must be called only before InitPluginsPreScript().
|
||||
*
|
||||
* @param dir The directory to search for plugins. Multiple directories
|
||||
* can be given by separating them with zeek::util::path_list_separator.
|
||||
*/
|
||||
void SearchDynamicPlugins(const std::string& dir);
|
||||
/**
|
||||
* Searches a set of directories for plugins. If a specified directory
|
||||
* does not contain a plugin itself, the method searches for plugins
|
||||
* recursively. For plugins found, the method makes them available for
|
||||
* later activation via ActivatePlugin().
|
||||
*
|
||||
* This must be called only before InitPluginsPreScript().
|
||||
*
|
||||
* @param dir The directory to search for plugins. Multiple directories
|
||||
* can be given by separating them with zeek::util::path_list_separator.
|
||||
*/
|
||||
void SearchDynamicPlugins(const std::string& dir);
|
||||
|
||||
/**
|
||||
* Activates a plugin that SearchDynamicPlugins() has previously discovered.
|
||||
* Activating a plugin involves loading its dynamic module, making its
|
||||
* bifs available, and adding its script paths to ZEEKPATH.
|
||||
*
|
||||
* This attempts to activate the plugin immediately. If that fails for
|
||||
* some reason, we schedule it to be retried later with
|
||||
* ActivateDynamicPlugins().
|
||||
*
|
||||
* @param name The name of the plugin, as found previously by
|
||||
·* SearchPlugin().
|
||||
*/
|
||||
void ActivateDynamicPlugin(const std::string& name);
|
||||
/**
|
||||
* Activates a plugin that SearchDynamicPlugins() has previously discovered.
|
||||
* Activating a plugin involves loading its dynamic module, making its
|
||||
* bifs available, and adding its script paths to ZEEKPATH.
|
||||
*
|
||||
* This attempts to activate the plugin immediately. If that fails for
|
||||
* some reason, we schedule it to be retried later with
|
||||
* ActivateDynamicPlugins().
|
||||
*
|
||||
* @param name The name of the plugin, as found previously by
|
||||
·* SearchPlugin().
|
||||
*/
|
||||
void ActivateDynamicPlugin(const std::string& name);
|
||||
|
||||
/**
|
||||
* Activates plugins that SearchDynamicPlugins() has previously discovered,
|
||||
* including any that have failed to load in prior calls to
|
||||
* ActivateDynamicPlugin(). Aborts if any plugins fails to activate.
|
||||
*
|
||||
* @param all If true, activates all plugins that are found. If false,
|
||||
* activates only those that should always be activated unconditionally,
|
||||
* as specified via the ZEEK_PLUGIN_ACTIVATE environment variable.
|
||||
*/
|
||||
void ActivateDynamicPlugins(bool all);
|
||||
/**
|
||||
* Activates plugins that SearchDynamicPlugins() has previously discovered,
|
||||
* including any that have failed to load in prior calls to
|
||||
* ActivateDynamicPlugin(). Aborts if any plugins fails to activate.
|
||||
*
|
||||
* @param all If true, activates all plugins that are found. If false,
|
||||
* activates only those that should always be activated unconditionally,
|
||||
* as specified via the ZEEK_PLUGIN_ACTIVATE environment variable.
|
||||
*/
|
||||
void ActivateDynamicPlugins(bool all);
|
||||
|
||||
/**
|
||||
* First-stage initialization of the manager. This is called early on
|
||||
* during Zeek's initialization, before any scripts are processed, and
|
||||
* forwards to the corresponding Plugin methods.
|
||||
*/
|
||||
void InitPreScript();
|
||||
/**
|
||||
* First-stage initialization of the manager. This is called early on
|
||||
* during Zeek's initialization, before any scripts are processed, and
|
||||
* forwards to the corresponding Plugin methods.
|
||||
*/
|
||||
void InitPreScript();
|
||||
|
||||
/**
|
||||
* Second-stage initialization of the manager. This is called in between
|
||||
* pre- and post-script to make BiFs available.
|
||||
*/
|
||||
void InitBifs();
|
||||
/**
|
||||
* Second-stage initialization of the manager. This is called in between
|
||||
* pre- and post-script to make BiFs available.
|
||||
*/
|
||||
void InitBifs();
|
||||
|
||||
/**
|
||||
* Third-stage initialization of the manager. This is called late during
|
||||
* Zeek's initialization after any scripts are processed, and forwards to
|
||||
* the corresponding Plugin methods.
|
||||
*/
|
||||
void InitPostScript();
|
||||
/**
|
||||
* Third-stage initialization of the manager. This is called late during
|
||||
* Zeek's initialization after any scripts are processed, and forwards to
|
||||
* the corresponding Plugin methods.
|
||||
*/
|
||||
void InitPostScript();
|
||||
|
||||
/**
|
||||
* Finalizes all plugins at termination time. This forwards to the
|
||||
* corresponding Plugin \a Done() methods.
|
||||
*/
|
||||
void FinishPlugins();
|
||||
/**
|
||||
* Finalizes all plugins at termination time. This forwards to the
|
||||
* corresponding Plugin \a Done() methods.
|
||||
*/
|
||||
void FinishPlugins();
|
||||
|
||||
/**
|
||||
* Returns a list of all available activated plugins. This includes all
|
||||
* that are compiled in statically, as well as those loaded dynamically
|
||||
* so far.
|
||||
*/
|
||||
plugin_list ActivePlugins() const;
|
||||
/**
|
||||
* Returns a list of all available activated plugins. This includes all
|
||||
* that are compiled in statically, as well as those loaded dynamically
|
||||
* so far.
|
||||
*/
|
||||
plugin_list ActivePlugins() const;
|
||||
|
||||
/**
|
||||
* Returns a list of all dynamic plugins that have been found, yet not
|
||||
* activated. The returned list contains pairs of plugin name and base
|
||||
* directory. Note that because they aren't activated, that's all
|
||||
* information we have access to.
|
||||
*/
|
||||
inactive_plugin_list InactivePlugins() const;
|
||||
/**
|
||||
* Returns a list of all dynamic plugins that have been found, yet not
|
||||
* activated. The returned list contains pairs of plugin name and base
|
||||
* directory. Note that because they aren't activated, that's all
|
||||
* information we have access to.
|
||||
*/
|
||||
inactive_plugin_list InactivePlugins() const;
|
||||
|
||||
/**
|
||||
* Returns a list of all available components, in any plugin, that
|
||||
* are derived from a specific class. The class is given as the
|
||||
* template parameter \c T.
|
||||
*/
|
||||
template <class T> std::list<T*> Components() const;
|
||||
/**
|
||||
* Returns a list of all available components, in any plugin, that
|
||||
* are derived from a specific class. The class is given as the
|
||||
* template parameter \c T.
|
||||
*/
|
||||
template<class T>
|
||||
std::list<T*> Components() const;
|
||||
|
||||
/**
|
||||
* Returns the (dynamic) plugin associated with a given filesystem
|
||||
* path. The path can be the plugin directory itself, or any path
|
||||
* inside it.
|
||||
*/
|
||||
Plugin* LookupPluginByPath(std::string_view path);
|
||||
/**
|
||||
* Returns the (dynamic) plugin associated with a given filesystem
|
||||
* path. The path can be the plugin directory itself, or any path
|
||||
* inside it.
|
||||
*/
|
||||
Plugin* LookupPluginByPath(std::string_view path);
|
||||
|
||||
/**
|
||||
* Returns true if there's at least one plugin interested in a given
|
||||
* hook.
|
||||
*
|
||||
* @param The hook to check.
|
||||
*
|
||||
* @return True if there's a plugin for that hook.
|
||||
*/
|
||||
bool HavePluginForHook(HookType hook) const
|
||||
{
|
||||
// Inline to avoid the function call.
|
||||
return hooks[hook] != nullptr;
|
||||
}
|
||||
/**
|
||||
* Returns true if there's at least one plugin interested in a given
|
||||
* hook.
|
||||
*
|
||||
* @param The hook to check.
|
||||
*
|
||||
* @return True if there's a plugin for that hook.
|
||||
*/
|
||||
bool HavePluginForHook(HookType hook) const {
|
||||
// Inline to avoid the function call.
|
||||
return hooks[hook] != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the hooks, with their priorities, that are currently
|
||||
* enabled for a given plugin.
|
||||
*
|
||||
* @param plugin The plugin to return the hooks for.
|
||||
*/
|
||||
std::list<std::pair<HookType, int>> HooksEnabledForPlugin(const Plugin* plugin) const;
|
||||
/**
|
||||
* Returns all the hooks, with their priorities, that are currently
|
||||
* enabled for a given plugin.
|
||||
*
|
||||
* @param plugin The plugin to return the hooks for.
|
||||
*/
|
||||
std::list<std::pair<HookType, int>> HooksEnabledForPlugin(const Plugin* plugin) const;
|
||||
|
||||
/**
|
||||
* Enables a hook for a given plugin.
|
||||
*
|
||||
* hook: The hook to enable.
|
||||
*
|
||||
* plugin: The plugin defining the hook.
|
||||
*
|
||||
* prio: The priority to associate with the plugin for this hook.
|
||||
*/
|
||||
void EnableHook(HookType hook, Plugin* plugin, int prio);
|
||||
/**
|
||||
* Enables a hook for a given plugin.
|
||||
*
|
||||
* hook: The hook to enable.
|
||||
*
|
||||
* plugin: The plugin defining the hook.
|
||||
*
|
||||
* prio: The priority to associate with the plugin for this hook.
|
||||
*/
|
||||
void EnableHook(HookType hook, Plugin* plugin, int prio);
|
||||
|
||||
/**
|
||||
* Disables a hook for a given plugin.
|
||||
*
|
||||
* hook: The hook to enable.
|
||||
*
|
||||
* plugin: The plugin that used to define the hook.
|
||||
*/
|
||||
void DisableHook(HookType hook, Plugin* plugin);
|
||||
/**
|
||||
* Disables a hook for a given plugin.
|
||||
*
|
||||
* hook: The hook to enable.
|
||||
*
|
||||
* plugin: The plugin that used to define the hook.
|
||||
*/
|
||||
void DisableHook(HookType hook, Plugin* plugin);
|
||||
|
||||
/**
|
||||
* Registers interest in an event by a plugin, even if there's no handler
|
||||
* for it. Normally a plugin receives events through HookQueueEvent()
|
||||
* only if Zeek actually has code to execute for it. By calling this
|
||||
* method, the plugin tells Zeek to raise the event even if there's no
|
||||
* corresponding handler; it will then go into HookQueueEvent() just as
|
||||
* any other.
|
||||
*
|
||||
* @param handler The event being interested in.
|
||||
*
|
||||
* @param plugin The plugin expressing interest.
|
||||
*/
|
||||
void RequestEvent(EventHandlerPtr handler, Plugin* plugin);
|
||||
/**
|
||||
* Registers interest in an event by a plugin, even if there's no handler
|
||||
* for it. Normally a plugin receives events through HookQueueEvent()
|
||||
* only if Zeek actually has code to execute for it. By calling this
|
||||
* method, the plugin tells Zeek to raise the event even if there's no
|
||||
* corresponding handler; it will then go into HookQueueEvent() just as
|
||||
* any other.
|
||||
*
|
||||
* @param handler The event being interested in.
|
||||
*
|
||||
* @param plugin The plugin expressing interest.
|
||||
*/
|
||||
void RequestEvent(EventHandlerPtr handler, Plugin* plugin);
|
||||
|
||||
/**
|
||||
* Register interest in the destruction of a Obj instance. When Zeek's
|
||||
* reference counting triggers the objects destructor to run, the \a
|
||||
* HookObjDtor will be called.
|
||||
*
|
||||
* @param handler The object being interested in.
|
||||
*
|
||||
* @param plugin The plugin expressing interest.
|
||||
*/
|
||||
void RequestObjDtor(Obj* obj, Plugin* plugin);
|
||||
/**
|
||||
* Register interest in the destruction of a Obj instance. When Zeek's
|
||||
* reference counting triggers the objects destructor to run, the \a
|
||||
* HookObjDtor will be called.
|
||||
*
|
||||
* @param handler The object being interested in.
|
||||
*
|
||||
* @param plugin The plugin expressing interest.
|
||||
*/
|
||||
void RequestObjDtor(Obj* obj, Plugin* plugin);
|
||||
|
||||
// Hook entry functions.
|
||||
// Hook entry functions.
|
||||
|
||||
/**
|
||||
* Hook that gives plugins a chance to take over loading an input
|
||||
* file. This method must be called between InitPreScript() and
|
||||
* InitPostScript() for each input file Zeek is about to load, either
|
||||
* given on the command line or via @load script directives. The hook can
|
||||
* take over the file, in which case Zeek must not further process it
|
||||
* otherwise.
|
||||
*
|
||||
* @return 1 if a plugin took over the file and loaded it successfully; 0
|
||||
* if a plugin took over the file but had trouble loading it; and -1 if
|
||||
* no plugin was interested in the file at all.
|
||||
*/
|
||||
virtual int HookLoadFile(const Plugin::LoadType type, const std::string& file,
|
||||
const std::string& resolved);
|
||||
/**
|
||||
* Hook that gives plugins a chance to take over loading an input
|
||||
* file. This method must be called between InitPreScript() and
|
||||
* InitPostScript() for each input file Zeek is about to load, either
|
||||
* given on the command line or via @load script directives. The hook can
|
||||
* take over the file, in which case Zeek must not further process it
|
||||
* otherwise.
|
||||
*
|
||||
* @return 1 if a plugin took over the file and loaded it successfully; 0
|
||||
* if a plugin took over the file but had trouble loading it; and -1 if
|
||||
* no plugin was interested in the file at all.
|
||||
*/
|
||||
virtual int HookLoadFile(const Plugin::LoadType type, const std::string& file, const std::string& resolved);
|
||||
|
||||
/**
|
||||
* Hook that gives plugins a chance to take over loading an input file,
|
||||
* including replacing the file's content. This method must be called
|
||||
* between InitPreScript() and InitPostScript() for each input file Zeek is
|
||||
* about to load, either given on the command line or via @load script
|
||||
* directives. The hook can take over the file, in which case Zeek must not
|
||||
* further process it otherwise; or provide its content, in which case Zeek
|
||||
* must use that and ignore the original file.
|
||||
*
|
||||
* @return tuple where the first element is 1 if a plugin took over the
|
||||
* file; 0 if a plugin took over the file but had trouble loading it; and
|
||||
* -1 if no plugin was interested in the file at all.
|
||||
*
|
||||
* If the plugins takes over by returning 1, there are two cases: if the
|
||||
* second tuple element remains unset, the plugin handled the loading
|
||||
* completely internally; the caller must not process it any further.
|
||||
* Alternatively, the plugin may optionally return the actual content to
|
||||
* use for the file as a string through the tuple's second element. If so,
|
||||
* the caller must ignore the file on disk and use that provided content
|
||||
* instead (including when there's actually no physical file in place on
|
||||
* disk at all).
|
||||
*/
|
||||
virtual std::pair<int, std::optional<std::string>>
|
||||
HookLoadFileExtended(const Plugin::LoadType type, const std::string& file,
|
||||
const std::string& resolved);
|
||||
/**
|
||||
* Hook that gives plugins a chance to take over loading an input file,
|
||||
* including replacing the file's content. This method must be called
|
||||
* between InitPreScript() and InitPostScript() for each input file Zeek is
|
||||
* about to load, either given on the command line or via @load script
|
||||
* directives. The hook can take over the file, in which case Zeek must not
|
||||
* further process it otherwise; or provide its content, in which case Zeek
|
||||
* must use that and ignore the original file.
|
||||
*
|
||||
* @return tuple where the first element is 1 if a plugin took over the
|
||||
* file; 0 if a plugin took over the file but had trouble loading it; and
|
||||
* -1 if no plugin was interested in the file at all.
|
||||
*
|
||||
* If the plugins takes over by returning 1, there are two cases: if the
|
||||
* second tuple element remains unset, the plugin handled the loading
|
||||
* completely internally; the caller must not process it any further.
|
||||
* Alternatively, the plugin may optionally return the actual content to
|
||||
* use for the file as a string through the tuple's second element. If so,
|
||||
* the caller must ignore the file on disk and use that provided content
|
||||
* instead (including when there's actually no physical file in place on
|
||||
* disk at all).
|
||||
*/
|
||||
virtual std::pair<int, std::optional<std::string>> HookLoadFileExtended(const Plugin::LoadType type,
|
||||
const std::string& file,
|
||||
const std::string& resolved);
|
||||
|
||||
/**
|
||||
* Hook that filters calls to a script function/event/hook.
|
||||
*
|
||||
* @param func The function to be called.
|
||||
*
|
||||
* @param parent The frame in which the function is being called.
|
||||
*
|
||||
* @param args The function call's arguments; they may be modified by the
|
||||
* method.
|
||||
*
|
||||
* @return If a plugin handled the call, a Val representing the result
|
||||
* to pass back to the interpreter (for void functions and events,
|
||||
* it may be any Val and must be ignored). If no plugin handled the call,
|
||||
* the method returns null.
|
||||
*/
|
||||
std::pair<bool, ValPtr> HookCallFunction(const Func* func, zeek::detail::Frame* parent,
|
||||
Args* args) const;
|
||||
/**
|
||||
* Hook that filters calls to a script function/event/hook.
|
||||
*
|
||||
* @param func The function to be called.
|
||||
*
|
||||
* @param parent The frame in which the function is being called.
|
||||
*
|
||||
* @param args The function call's arguments; they may be modified by the
|
||||
* method.
|
||||
*
|
||||
* @return If a plugin handled the call, a Val representing the result
|
||||
* to pass back to the interpreter (for void functions and events,
|
||||
* it may be any Val and must be ignored). If no plugin handled the call,
|
||||
* the method returns null.
|
||||
*/
|
||||
std::pair<bool, ValPtr> HookCallFunction(const Func* func, zeek::detail::Frame* parent, Args* args) const;
|
||||
|
||||
/**
|
||||
* Hook that filters the queuing of an event.
|
||||
*
|
||||
* @param event The event to be queued; it may be modified.
|
||||
*
|
||||
* @return Returns true if a plugin handled the queuing; in that case
|
||||
* the plugin will have taken ownership.
|
||||
*/
|
||||
bool HookQueueEvent(Event* event) const;
|
||||
/**
|
||||
* Hook that filters the queuing of an event.
|
||||
*
|
||||
* @param event The event to be queued; it may be modified.
|
||||
*
|
||||
* @return Returns true if a plugin handled the queuing; in that case
|
||||
* the plugin will have taken ownership.
|
||||
*/
|
||||
bool HookQueueEvent(Event* event) const;
|
||||
|
||||
/**
|
||||
* Hook that informs plugins about an update in network time.
|
||||
*
|
||||
* @param network_time The new network time.
|
||||
*/
|
||||
void HookUpdateNetworkTime(double network_time) const;
|
||||
/**
|
||||
* Hook that informs plugins about an update in network time.
|
||||
*
|
||||
* @param network_time The new network time.
|
||||
*/
|
||||
void HookUpdateNetworkTime(double network_time) const;
|
||||
|
||||
/**
|
||||
* Hook that executes when a connection's initial analyzer tree
|
||||
* has been fully set up. The hook can manipulate the tree at this time,
|
||||
* for example by adding further analyzers.
|
||||
*
|
||||
* @param conn The connection.
|
||||
*/
|
||||
void HookSetupAnalyzerTree(Connection* conn) const;
|
||||
/**
|
||||
* Hook that executes when a connection's initial analyzer tree
|
||||
* has been fully set up. The hook can manipulate the tree at this time,
|
||||
* for example by adding further analyzers.
|
||||
*
|
||||
* @param conn The connection.
|
||||
*/
|
||||
void HookSetupAnalyzerTree(Connection* conn) const;
|
||||
|
||||
/**
|
||||
* Hook that informs plugins that the event queue is being drained.
|
||||
*/
|
||||
void HookDrainEvents() const;
|
||||
/**
|
||||
* Hook that informs plugins that the event queue is being drained.
|
||||
*/
|
||||
void HookDrainEvents() const;
|
||||
|
||||
/**
|
||||
* Hook that informs plugins that an Obj is being destroyed. Will be
|
||||
* called only for objects that a plugin has expressed interest in.
|
||||
*/
|
||||
void HookObjDtor(void* obj) const;
|
||||
/**
|
||||
* Hook that informs plugins that an Obj is being destroyed. Will be
|
||||
* called only for objects that a plugin has expressed interest in.
|
||||
*/
|
||||
void HookObjDtor(void* obj) const;
|
||||
|
||||
/**
|
||||
* Hook into log initialization. This method will be called when a
|
||||
* logging writer is created. A writer represents a single logging
|
||||
* filter. The method is called in the main thread, on the node that
|
||||
* causes a log line to be written. It will _not_ be called on the logger
|
||||
* node. The function will be called once for every instantiated writer.
|
||||
*
|
||||
* @param writer The name of the writer being instantiated.
|
||||
*
|
||||
* @param instantiating_filter Name of the filter causing the
|
||||
* writer instantiation.
|
||||
*
|
||||
* @param local True if the filter is logging locally (writer
|
||||
* thread will be located in same process).
|
||||
*
|
||||
* @param remote True if filter is logging remotely (writer thread
|
||||
* will be located in different thread, typically
|
||||
* in manager or logger node).
|
||||
*
|
||||
* @param info WriterBackend::WriterInfo with information about the writer.
|
||||
*
|
||||
* @param num_fields number of fields in the record being written.
|
||||
*
|
||||
* @param fields threading::Field description of the fields being logged.
|
||||
*/
|
||||
void HookLogInit(const std::string& writer, const std::string& instantiating_filter, bool local,
|
||||
bool remote, const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields) const;
|
||||
/**
|
||||
* Hook into log initialization. This method will be called when a
|
||||
* logging writer is created. A writer represents a single logging
|
||||
* filter. The method is called in the main thread, on the node that
|
||||
* causes a log line to be written. It will _not_ be called on the logger
|
||||
* node. The function will be called once for every instantiated writer.
|
||||
*
|
||||
* @param writer The name of the writer being instantiated.
|
||||
*
|
||||
* @param instantiating_filter Name of the filter causing the
|
||||
* writer instantiation.
|
||||
*
|
||||
* @param local True if the filter is logging locally (writer
|
||||
* thread will be located in same process).
|
||||
*
|
||||
* @param remote True if filter is logging remotely (writer thread
|
||||
* will be located in different thread, typically
|
||||
* in manager or logger node).
|
||||
*
|
||||
* @param info WriterBackend::WriterInfo with information about the writer.
|
||||
*
|
||||
* @param num_fields number of fields in the record being written.
|
||||
*
|
||||
* @param fields threading::Field description of the fields being logged.
|
||||
*/
|
||||
void HookLogInit(const std::string& writer, const std::string& instantiating_filter, bool local, bool remote,
|
||||
const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields) const;
|
||||
|
||||
/**
|
||||
* Hook into log writing. This method will be called for each log line
|
||||
* being written by each writer. Each writer represents a single logging
|
||||
* filter. The method is called in the main thread, on the node that
|
||||
* causes a log line to be written. It will _not_ be called on the logger
|
||||
* node.
|
||||
* This function allows plugins to modify or skip logging of information.
|
||||
* Note - once a log line is skipped (by returning false), it will not
|
||||
* passed on to hooks that have not yet been called.
|
||||
*
|
||||
* @param writer The name of the writer.
|
||||
*
|
||||
* @param filter Name of the filter being written to.
|
||||
*
|
||||
* @param info WriterBackend::WriterInfo with information about the writer.
|
||||
*
|
||||
* @param num_fields number of fields in the record being written.
|
||||
*
|
||||
* @param fields threading::Field description of the fields being logged.
|
||||
*
|
||||
* @param vals threading::Values containing the values being written. Values
|
||||
* can be modified in the Hook.
|
||||
*
|
||||
* @return true if log line should be written, false if log line should be
|
||||
* skipped and not passed on to the writer.
|
||||
*/
|
||||
bool HookLogWrite(const std::string& writer, const std::string& filter,
|
||||
const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields, threading::Value** vals) const;
|
||||
/**
|
||||
* Hook into log writing. This method will be called for each log line
|
||||
* being written by each writer. Each writer represents a single logging
|
||||
* filter. The method is called in the main thread, on the node that
|
||||
* causes a log line to be written. It will _not_ be called on the logger
|
||||
* node.
|
||||
* This function allows plugins to modify or skip logging of information.
|
||||
* Note - once a log line is skipped (by returning false), it will not
|
||||
* passed on to hooks that have not yet been called.
|
||||
*
|
||||
* @param writer The name of the writer.
|
||||
*
|
||||
* @param filter Name of the filter being written to.
|
||||
*
|
||||
* @param info WriterBackend::WriterInfo with information about the writer.
|
||||
*
|
||||
* @param num_fields number of fields in the record being written.
|
||||
*
|
||||
* @param fields threading::Field description of the fields being logged.
|
||||
*
|
||||
* @param vals threading::Values containing the values being written. Values
|
||||
* can be modified in the Hook.
|
||||
*
|
||||
* @return true if log line should be written, false if log line should be
|
||||
* skipped and not passed on to the writer.
|
||||
*/
|
||||
bool HookLogWrite(const std::string& writer, const std::string& filter,
|
||||
const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields, threading::Value** vals) const;
|
||||
|
||||
/**
|
||||
* Hook into reporting. This method will be called for each reporter call
|
||||
* made; this includes weirds. The method cannot manipulate the data at
|
||||
* the current time; however it is possible to prevent script-side events
|
||||
* from being called by returning false.
|
||||
*
|
||||
* @param prefix The prefix passed by the reporter framework
|
||||
*
|
||||
* @param event The event to be called
|
||||
*
|
||||
* @param conn The associated connection
|
||||
*
|
||||
* @param addl Additional Zeek values; typically will be passed to the event
|
||||
* by the reporter framework.
|
||||
*
|
||||
* @param location True if event expects location information
|
||||
*
|
||||
* @param location1 First location
|
||||
*
|
||||
* @param location2 Second location
|
||||
*
|
||||
* @param time True if event expects time information
|
||||
*
|
||||
* @param message Message supplied by the reporter framework
|
||||
*
|
||||
* @return true if event should be called by the reporter framework, false
|
||||
* if the event call should be skipped
|
||||
*/
|
||||
bool HookReporter(const std::string& prefix, const EventHandlerPtr event,
|
||||
const Connection* conn, const ValPList* addl, bool location,
|
||||
const zeek::detail::Location* location1,
|
||||
const zeek::detail::Location* location2, bool time,
|
||||
const std::string& message);
|
||||
/**
|
||||
* Hook into reporting. This method will be called for each reporter call
|
||||
* made; this includes weirds. The method cannot manipulate the data at
|
||||
* the current time; however it is possible to prevent script-side events
|
||||
* from being called by returning false.
|
||||
*
|
||||
* @param prefix The prefix passed by the reporter framework
|
||||
*
|
||||
* @param event The event to be called
|
||||
*
|
||||
* @param conn The associated connection
|
||||
*
|
||||
* @param addl Additional Zeek values; typically will be passed to the event
|
||||
* by the reporter framework.
|
||||
*
|
||||
* @param location True if event expects location information
|
||||
*
|
||||
* @param location1 First location
|
||||
*
|
||||
* @param location2 Second location
|
||||
*
|
||||
* @param time True if event expects time information
|
||||
*
|
||||
* @param message Message supplied by the reporter framework
|
||||
*
|
||||
* @return true if event should be called by the reporter framework, false
|
||||
* if the event call should be skipped
|
||||
*/
|
||||
bool HookReporter(const std::string& prefix, const EventHandlerPtr event, const Connection* conn,
|
||||
const ValPList* addl, bool location, const zeek::detail::Location* location1,
|
||||
const zeek::detail::Location* location2, bool time, const std::string& message);
|
||||
|
||||
/**
|
||||
* Hook for packets that are considered unprocessed by an Analyzer. This
|
||||
* typically means that a packet has not had a log entry written for it by
|
||||
* the time analysis finishes.
|
||||
*
|
||||
* @param packet The data for an unprocessed packet
|
||||
*/
|
||||
void HookUnprocessedPacket(const Packet* packet) const;
|
||||
/**
|
||||
* Hook for packets that are considered unprocessed by an Analyzer. This
|
||||
* typically means that a packet has not had a log entry written for it by
|
||||
* the time analysis finishes.
|
||||
*
|
||||
* @param packet The data for an unprocessed packet
|
||||
*/
|
||||
void HookUnprocessedPacket(const Packet* packet) const;
|
||||
|
||||
/**
|
||||
* Internal method that registers a freshly instantiated plugin with
|
||||
* the manager.
|
||||
*
|
||||
* @param plugin The plugin to register. The method does not take
|
||||
* ownership, yet assumes the pointer will stay valid at least until
|
||||
* the Manager is destroyed.
|
||||
*/
|
||||
static void RegisterPlugin(Plugin* plugin);
|
||||
/**
|
||||
* Internal method that registers a freshly instantiated plugin with
|
||||
* the manager.
|
||||
*
|
||||
* @param plugin The plugin to register. The method does not take
|
||||
* ownership, yet assumes the pointer will stay valid at least until
|
||||
* the Manager is destroyed.
|
||||
*/
|
||||
static void RegisterPlugin(Plugin* plugin);
|
||||
|
||||
/**
|
||||
* Internal method that registers a bif file's init function for a
|
||||
* plugin.
|
||||
*
|
||||
* @param plugin The plugin to register the function for.
|
||||
*
|
||||
* @param c The init function to register.
|
||||
*/
|
||||
static void RegisterBifFile(const char* plugin, bif_init_func c);
|
||||
/**
|
||||
* Internal method that registers a bif file's init function for a
|
||||
* plugin.
|
||||
*
|
||||
* @param plugin The plugin to register the function for.
|
||||
*
|
||||
* @param c The init function to register.
|
||||
*/
|
||||
static void RegisterBifFile(const char* plugin, bif_init_func c);
|
||||
|
||||
/**
|
||||
* Adds the paths from built-in plugins (e.g. from --include-plugins)
|
||||
* to ZEEKPATH so they are loaded correctly.
|
||||
*/
|
||||
void ExtendZeekPathForPlugins();
|
||||
/**
|
||||
* Adds the paths from built-in plugins (e.g. from --include-plugins)
|
||||
* to ZEEKPATH so they are loaded correctly.
|
||||
*/
|
||||
void ExtendZeekPathForPlugins();
|
||||
|
||||
private:
|
||||
bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found,
|
||||
std::vector<std::string>* errors);
|
||||
void UpdateInputFiles();
|
||||
void MetaHookPre(HookType hook, const HookArgumentList& args) const;
|
||||
void MetaHookPost(HookType hook, const HookArgumentList& args,
|
||||
const HookArgument& result) const;
|
||||
bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found, std::vector<std::string>* errors);
|
||||
void UpdateInputFiles();
|
||||
void MetaHookPre(HookType hook, const HookArgumentList& args) const;
|
||||
void MetaHookPost(HookType hook, const HookArgumentList& args, const HookArgument& result) const;
|
||||
|
||||
// Directories that have already been searched for dynamic plugins.
|
||||
// Used to prevent multiple searches of the same dirs (e.g. via symlinks).
|
||||
// The paths stored in the set are made canonical via calls to
|
||||
// std::filesystem::canonical().
|
||||
std::set<std::string, std::less<>> searched_dirs;
|
||||
// Directories that have already been searched for dynamic plugins.
|
||||
// Used to prevent multiple searches of the same dirs (e.g. via symlinks).
|
||||
// The paths stored in the set are made canonical via calls to
|
||||
// std::filesystem::canonical().
|
||||
std::set<std::string, std::less<>> searched_dirs;
|
||||
|
||||
// Plugins that were explicitly requested to be activated, but failed to
|
||||
// load at first.
|
||||
std::set<std::string> requested_plugins;
|
||||
// Plugins that were explicitly requested to be activated, but failed to
|
||||
// load at first.
|
||||
std::set<std::string> requested_plugins;
|
||||
|
||||
// All found dynamic plugins, mapping their names to base directory.
|
||||
using dynamic_plugin_map = std::map<std::string, std::string>;
|
||||
dynamic_plugin_map dynamic_plugins;
|
||||
// All found dynamic plugins, mapping their names to base directory.
|
||||
using dynamic_plugin_map = std::map<std::string, std::string>;
|
||||
dynamic_plugin_map dynamic_plugins;
|
||||
|
||||
// We temporarily buffer scripts to load to get them to load in the
|
||||
// right order.
|
||||
using file_list = std::list<std::string>;
|
||||
file_list scripts_to_load;
|
||||
// We temporarily buffer scripts to load to get them to load in the
|
||||
// right order.
|
||||
using file_list = std::list<std::string>;
|
||||
file_list scripts_to_load;
|
||||
|
||||
bool init; // Flag indicating whether InitPreScript() has run yet.
|
||||
bool init; // Flag indicating whether InitPreScript() has run yet.
|
||||
|
||||
// A hook list keeps pairs of plugin and priority interested in a
|
||||
// given hook.
|
||||
using hook_list = std::list<std::pair<int, Plugin*>>;
|
||||
// A hook list keeps pairs of plugin and priority interested in a
|
||||
// given hook.
|
||||
using hook_list = std::list<std::pair<int, Plugin*>>;
|
||||
|
||||
// An array indexed by HookType. An entry is null if there's no hook
|
||||
// of that type enabled.
|
||||
hook_list** hooks;
|
||||
// An array indexed by HookType. An entry is null if there's no hook
|
||||
// of that type enabled.
|
||||
hook_list** hooks;
|
||||
|
||||
// A map of all the top-level plugin directories.
|
||||
std::map<std::string, Plugin*> plugins_by_path;
|
||||
// A map of all the top-level plugin directories.
|
||||
std::map<std::string, Plugin*> plugins_by_path;
|
||||
|
||||
// Helpers providing access to current state during dlopen().
|
||||
static Plugin* current_plugin;
|
||||
static const char* current_dir;
|
||||
static const char* current_sopath;
|
||||
// Helpers providing access to current state during dlopen().
|
||||
static Plugin* current_plugin;
|
||||
static const char* current_dir;
|
||||
static const char* current_sopath;
|
||||
|
||||
// Returns a modifiable list of all plugins, both static and dynamic.
|
||||
// This is a static method so that plugins can register themselves
|
||||
// even before the manager exists.
|
||||
static plugin_list* ActivePluginsInternal();
|
||||
// Returns a modifiable list of all plugins, both static and dynamic.
|
||||
// This is a static method so that plugins can register themselves
|
||||
// even before the manager exists.
|
||||
static plugin_list* ActivePluginsInternal();
|
||||
|
||||
using bif_init_func_list = std::list<bif_init_func>;
|
||||
using bif_init_func_map = std::map<std::string, bif_init_func_list*>;
|
||||
using bif_init_func_list = std::list<bif_init_func>;
|
||||
using bif_init_func_map = std::map<std::string, bif_init_func_list*>;
|
||||
|
||||
// Returns a modifiable map of all bif files. This is a static method
|
||||
// so that plugins can register their bifs even before the manager
|
||||
// exists.
|
||||
static bif_init_func_map* BifFilesInternal();
|
||||
};
|
||||
// Returns a modifiable map of all bif files. This is a static method
|
||||
// so that plugins can register their bifs even before the manager
|
||||
// exists.
|
||||
static bif_init_func_map* BifFilesInternal();
|
||||
};
|
||||
|
||||
template <class T> std::list<T*> Manager::Components() const
|
||||
{
|
||||
std::list<T*> result;
|
||||
template<class T>
|
||||
std::list<T*> Manager::Components() const {
|
||||
std::list<T*> result;
|
||||
|
||||
for ( plugin_list::const_iterator p = ActivePluginsInternal()->begin();
|
||||
p != ActivePluginsInternal()->end(); p++ )
|
||||
{
|
||||
component_list components = (*p)->Components();
|
||||
for ( plugin_list::const_iterator p = ActivePluginsInternal()->begin(); p != ActivePluginsInternal()->end(); p++ ) {
|
||||
component_list components = (*p)->Components();
|
||||
|
||||
for ( component_list::const_iterator c = components.begin(); c != components.end(); c++ )
|
||||
{
|
||||
T* t = dynamic_cast<T*>(*c);
|
||||
for ( component_list::const_iterator c = components.begin(); c != components.end(); c++ ) {
|
||||
T* t = dynamic_cast<T*>(*c);
|
||||
|
||||
if ( t )
|
||||
result.push_back(t);
|
||||
}
|
||||
}
|
||||
if ( t )
|
||||
result.push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
namespace detail {
|
||||
|
||||
/**
|
||||
* Internal class used by bifcl-generated code to register its init functions at runtime.
|
||||
*/
|
||||
class __RegisterBif
|
||||
{
|
||||
class __RegisterBif {
|
||||
public:
|
||||
__RegisterBif(const char* plugin, Manager::bif_init_func init)
|
||||
{
|
||||
Manager::RegisterBifFile(plugin, init);
|
||||
}
|
||||
};
|
||||
__RegisterBif(const char* plugin, Manager::bif_init_func init) { Manager::RegisterBifFile(plugin, init); }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace plugin
|
||||
} // namespace detail
|
||||
} // namespace plugin
|
||||
|
||||
extern plugin::Manager* plugin_mgr;
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
|
|
@ -14,535 +14,406 @@
|
|||
#include "zeek/plugin/Manager.h"
|
||||
#include "zeek/threading/SerialTypes.h"
|
||||
|
||||
namespace zeek::plugin
|
||||
{
|
||||
|
||||
const char* hook_name(HookType h)
|
||||
{
|
||||
static constexpr const char* hook_names[int(NUM_HOOKS) + 1] = {
|
||||
// Order must match that of HookType.
|
||||
"LoadFile",
|
||||
"LoadFileExtended",
|
||||
"CallFunction",
|
||||
"QueueEvent",
|
||||
"DrainEvents",
|
||||
"UpdateNetworkTime",
|
||||
"SetupAnalyzerTree",
|
||||
"LogInit",
|
||||
"LogWrite",
|
||||
"Reporter",
|
||||
"UnprocessedPacket",
|
||||
"ObjDtor",
|
||||
// MetaHooks
|
||||
"MetaHookPre",
|
||||
"MetaHookPost",
|
||||
// End marker.
|
||||
"<end>",
|
||||
};
|
||||
|
||||
return hook_names[int(h)];
|
||||
}
|
||||
|
||||
BifItem::BifItem(const std::string& arg_id, Type arg_type)
|
||||
{
|
||||
id = arg_id;
|
||||
type = arg_type;
|
||||
}
|
||||
|
||||
BifItem::BifItem(const BifItem& other)
|
||||
{
|
||||
id = other.id;
|
||||
type = other.type;
|
||||
}
|
||||
|
||||
BifItem& BifItem::operator=(const BifItem& other)
|
||||
{
|
||||
if ( this != &other )
|
||||
{
|
||||
id = other.id;
|
||||
type = other.type;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void HookArgument::Describe(ODesc* d) const
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case BOOL:
|
||||
d->Add(arg.bool_ ? "true" : "false");
|
||||
break;
|
||||
|
||||
case DOUBLE:
|
||||
d->Add(arg.double_);
|
||||
break;
|
||||
|
||||
case EVENT:
|
||||
if ( arg.event )
|
||||
{
|
||||
d->Add(arg.event->Handler()->Name());
|
||||
d->Add("(");
|
||||
describe_vals(arg.event->Args(), d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case CONN:
|
||||
if ( arg.conn )
|
||||
arg.conn->Describe(d);
|
||||
break;
|
||||
|
||||
case FUNC_RESULT:
|
||||
if ( func_result.first )
|
||||
{
|
||||
if ( func_result.second )
|
||||
func_result.second->Describe(d);
|
||||
else
|
||||
d->Add("<null>");
|
||||
}
|
||||
else
|
||||
d->Add("<no result>");
|
||||
|
||||
break;
|
||||
|
||||
case FRAME:
|
||||
if ( arg.frame )
|
||||
d->Add("<frame>");
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case FUNC:
|
||||
if ( arg.func )
|
||||
d->Add(arg.func->Name());
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case INT:
|
||||
d->Add(arg.int_);
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
d->Add(arg_string);
|
||||
break;
|
||||
|
||||
case VAL:
|
||||
if ( arg.val )
|
||||
arg.val->Describe(d);
|
||||
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case VAL_LIST:
|
||||
if ( arg.vals )
|
||||
{
|
||||
d->Add("(");
|
||||
describe_vals(arg.vals, d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case ARG_LIST:
|
||||
if ( arg.args )
|
||||
{
|
||||
d->Add("(");
|
||||
describe_vals(*arg.args, d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case VOID:
|
||||
d->Add("<void>");
|
||||
break;
|
||||
|
||||
case VOIDP:
|
||||
d->Add("<void ptr>");
|
||||
break;
|
||||
|
||||
case WRITER_INFO:
|
||||
{
|
||||
d->Add(arg.winfo->path);
|
||||
d->Add("(");
|
||||
d->Add(arg.winfo->network_time);
|
||||
d->Add(",");
|
||||
d->Add(arg.winfo->rotation_interval);
|
||||
d->Add(",");
|
||||
d->Add(arg.winfo->rotation_base);
|
||||
|
||||
if ( arg.winfo->config.size() > 0 )
|
||||
{
|
||||
bool first = true;
|
||||
d->Add("config: {");
|
||||
|
||||
for ( auto& v : arg.winfo->config )
|
||||
{
|
||||
if ( ! first )
|
||||
d->Add(", ");
|
||||
|
||||
d->Add(v.first);
|
||||
d->Add(": ");
|
||||
d->Add(v.second);
|
||||
first = false;
|
||||
}
|
||||
|
||||
d->Add("}");
|
||||
}
|
||||
|
||||
d->Add(")");
|
||||
}
|
||||
break;
|
||||
|
||||
case THREAD_FIELDS:
|
||||
{
|
||||
d->Add("{");
|
||||
|
||||
for ( int i = 0; i < tfields.first; i++ )
|
||||
{
|
||||
const threading::Field* f = tfields.second[i];
|
||||
|
||||
if ( i > 0 )
|
||||
d->Add(", ");
|
||||
|
||||
d->Add(f->name);
|
||||
d->Add(" (");
|
||||
d->Add(f->TypeName());
|
||||
d->Add(")");
|
||||
}
|
||||
|
||||
d->Add("}");
|
||||
}
|
||||
break;
|
||||
|
||||
case LOCATION:
|
||||
if ( arg.loc )
|
||||
{
|
||||
arg.loc->Describe(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Add("<no location>");
|
||||
}
|
||||
break;
|
||||
|
||||
case INPUT_FILE:
|
||||
{
|
||||
d->Add("(");
|
||||
d->Add(input_file.first);
|
||||
d->Add(", ");
|
||||
if ( input_file.second )
|
||||
d->Add(input_file.second->substr(0, 20)); // cut content off
|
||||
else
|
||||
d->Add("<no content>");
|
||||
|
||||
d->Add(")");
|
||||
break;
|
||||
}
|
||||
|
||||
case PACKET:
|
||||
d->Add("<packet>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Plugin::Plugin()
|
||||
{
|
||||
dynamic = false;
|
||||
Manager::RegisterPlugin(this);
|
||||
}
|
||||
|
||||
Plugin::~Plugin()
|
||||
{
|
||||
Done();
|
||||
}
|
||||
|
||||
void Plugin::DoConfigure()
|
||||
{
|
||||
config = Configure();
|
||||
}
|
||||
|
||||
const std::string& Plugin::Name() const
|
||||
{
|
||||
return config.name;
|
||||
}
|
||||
|
||||
const std::string& Plugin::Description() const
|
||||
{
|
||||
return config.description;
|
||||
}
|
||||
|
||||
VersionNumber Plugin::Version() const
|
||||
{
|
||||
return config.version;
|
||||
}
|
||||
|
||||
bool Plugin::DynamicPlugin() const
|
||||
{
|
||||
return dynamic;
|
||||
}
|
||||
|
||||
const std::string& Plugin::PluginDirectory() const
|
||||
{
|
||||
return base_dir;
|
||||
}
|
||||
|
||||
const std::string& Plugin::PluginPath() const
|
||||
{
|
||||
return sopath;
|
||||
}
|
||||
|
||||
void Plugin::SetPluginLocation(const std::string& arg_dir, const std::string& arg_sopath)
|
||||
{
|
||||
base_dir = arg_dir;
|
||||
sopath = arg_sopath;
|
||||
}
|
||||
|
||||
void Plugin::SetDynamic(bool is_dynamic)
|
||||
{
|
||||
dynamic = is_dynamic;
|
||||
}
|
||||
|
||||
void Plugin::InitPreScript() { }
|
||||
|
||||
void Plugin::InitPostScript() { }
|
||||
|
||||
Plugin::bif_item_list Plugin::BifItems() const
|
||||
{
|
||||
return bif_items;
|
||||
}
|
||||
|
||||
void Plugin::Done()
|
||||
{
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
|
||||
delete *i;
|
||||
|
||||
components.clear();
|
||||
}
|
||||
|
||||
Plugin::component_list Plugin::Components() const
|
||||
{
|
||||
return components;
|
||||
}
|
||||
|
||||
static bool component_cmp(const Component* a, const Component* b)
|
||||
{
|
||||
return a->Name() < b->Name();
|
||||
}
|
||||
|
||||
bool Plugin::LoadZeekFile(const std::string& file)
|
||||
{
|
||||
::add_input_file(file.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Plugin::AddBifItem(const std::string& name, BifItem::Type type)
|
||||
{
|
||||
BifItem bi(name, (BifItem::Type)type);
|
||||
bif_items.push_back(bi);
|
||||
}
|
||||
|
||||
void Plugin::AddComponent(Component* c)
|
||||
{
|
||||
components.push_back(c);
|
||||
|
||||
// Sort components by name to make sure we have a deterministic
|
||||
// order.
|
||||
components.sort(component_cmp);
|
||||
}
|
||||
|
||||
Plugin::hook_list Plugin::EnabledHooks() const
|
||||
{
|
||||
return plugin_mgr->HooksEnabledForPlugin(this);
|
||||
}
|
||||
|
||||
void Plugin::EnableHook(HookType hook, int priority)
|
||||
{
|
||||
plugin_mgr->EnableHook(hook, this, priority);
|
||||
}
|
||||
|
||||
void Plugin::DisableHook(HookType hook)
|
||||
{
|
||||
plugin_mgr->DisableHook(hook, this);
|
||||
}
|
||||
|
||||
void Plugin::RequestEvent(EventHandlerPtr handler)
|
||||
{
|
||||
plugin_mgr->RequestEvent(handler, this);
|
||||
}
|
||||
|
||||
void Plugin::RequestObjDtor(Obj* obj)
|
||||
{
|
||||
plugin_mgr->RequestObjDtor(obj, this);
|
||||
}
|
||||
|
||||
int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std::string& resolved)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const LoadType type,
|
||||
const std::string& file,
|
||||
const std::string& resolved)
|
||||
{
|
||||
return std::make_pair(-1, std::nullopt);
|
||||
}
|
||||
|
||||
std::pair<bool, ValPtr> Plugin::HookFunctionCall(const Func* func, zeek::detail::Frame* parent,
|
||||
Args* args)
|
||||
{
|
||||
return {false, nullptr};
|
||||
}
|
||||
|
||||
bool Plugin::HookQueueEvent(Event* event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Plugin::HookDrainEvents() { }
|
||||
|
||||
void Plugin::HookUpdateNetworkTime(double network_time) { }
|
||||
|
||||
void Plugin::HookSetupAnalyzerTree(Connection* conn) { }
|
||||
|
||||
void Plugin::HookObjDtor(void* obj) { }
|
||||
|
||||
void Plugin::HookLogInit(const std::string& writer, const std::string& instantiating_filter,
|
||||
bool local, bool remote, const logging::WriterBackend::WriterInfo& info,
|
||||
int num_fields, const threading::Field* const* fields)
|
||||
{
|
||||
}
|
||||
namespace zeek::plugin {
|
||||
|
||||
const char* hook_name(HookType h) {
|
||||
static constexpr const char* hook_names[int(NUM_HOOKS) + 1] = {
|
||||
// Order must match that of HookType.
|
||||
"LoadFile",
|
||||
"LoadFileExtended",
|
||||
"CallFunction",
|
||||
"QueueEvent",
|
||||
"DrainEvents",
|
||||
"UpdateNetworkTime",
|
||||
"SetupAnalyzerTree",
|
||||
"LogInit",
|
||||
"LogWrite",
|
||||
"Reporter",
|
||||
"UnprocessedPacket",
|
||||
"ObjDtor",
|
||||
// MetaHooks
|
||||
"MetaHookPre",
|
||||
"MetaHookPost",
|
||||
// End marker.
|
||||
"<end>",
|
||||
};
|
||||
|
||||
return hook_names[int(h)];
|
||||
}
|
||||
|
||||
BifItem::BifItem(const std::string& arg_id, Type arg_type) {
|
||||
id = arg_id;
|
||||
type = arg_type;
|
||||
}
|
||||
|
||||
BifItem::BifItem(const BifItem& other) {
|
||||
id = other.id;
|
||||
type = other.type;
|
||||
}
|
||||
|
||||
BifItem& BifItem::operator=(const BifItem& other) {
|
||||
if ( this != &other ) {
|
||||
id = other.id;
|
||||
type = other.type;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void HookArgument::Describe(ODesc* d) const {
|
||||
switch ( type ) {
|
||||
case BOOL: d->Add(arg.bool_ ? "true" : "false"); break;
|
||||
|
||||
case DOUBLE: d->Add(arg.double_); break;
|
||||
|
||||
case EVENT:
|
||||
if ( arg.event ) {
|
||||
d->Add(arg.event->Handler()->Name());
|
||||
d->Add("(");
|
||||
describe_vals(arg.event->Args(), d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case CONN:
|
||||
if ( arg.conn )
|
||||
arg.conn->Describe(d);
|
||||
break;
|
||||
|
||||
case FUNC_RESULT:
|
||||
if ( func_result.first ) {
|
||||
if ( func_result.second )
|
||||
func_result.second->Describe(d);
|
||||
else
|
||||
d->Add("<null>");
|
||||
}
|
||||
else
|
||||
d->Add("<no result>");
|
||||
|
||||
break;
|
||||
|
||||
case FRAME:
|
||||
if ( arg.frame )
|
||||
d->Add("<frame>");
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case FUNC:
|
||||
if ( arg.func )
|
||||
d->Add(arg.func->Name());
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case INT: d->Add(arg.int_); break;
|
||||
|
||||
case STRING: d->Add(arg_string); break;
|
||||
|
||||
case VAL:
|
||||
if ( arg.val )
|
||||
arg.val->Describe(d);
|
||||
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case VAL_LIST:
|
||||
if ( arg.vals ) {
|
||||
d->Add("(");
|
||||
describe_vals(arg.vals, d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case ARG_LIST:
|
||||
if ( arg.args ) {
|
||||
d->Add("(");
|
||||
describe_vals(*arg.args, d);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("<null>");
|
||||
break;
|
||||
|
||||
case VOID: d->Add("<void>"); break;
|
||||
|
||||
case VOIDP: d->Add("<void ptr>"); break;
|
||||
|
||||
case WRITER_INFO: {
|
||||
d->Add(arg.winfo->path);
|
||||
d->Add("(");
|
||||
d->Add(arg.winfo->network_time);
|
||||
d->Add(",");
|
||||
d->Add(arg.winfo->rotation_interval);
|
||||
d->Add(",");
|
||||
d->Add(arg.winfo->rotation_base);
|
||||
|
||||
if ( arg.winfo->config.size() > 0 ) {
|
||||
bool first = true;
|
||||
d->Add("config: {");
|
||||
|
||||
for ( auto& v : arg.winfo->config ) {
|
||||
if ( ! first )
|
||||
d->Add(", ");
|
||||
|
||||
d->Add(v.first);
|
||||
d->Add(": ");
|
||||
d->Add(v.second);
|
||||
first = false;
|
||||
}
|
||||
|
||||
d->Add("}");
|
||||
}
|
||||
|
||||
d->Add(")");
|
||||
} break;
|
||||
|
||||
case THREAD_FIELDS: {
|
||||
d->Add("{");
|
||||
|
||||
for ( int i = 0; i < tfields.first; i++ ) {
|
||||
const threading::Field* f = tfields.second[i];
|
||||
|
||||
if ( i > 0 )
|
||||
d->Add(", ");
|
||||
|
||||
d->Add(f->name);
|
||||
d->Add(" (");
|
||||
d->Add(f->TypeName());
|
||||
d->Add(")");
|
||||
}
|
||||
|
||||
d->Add("}");
|
||||
} break;
|
||||
|
||||
case LOCATION:
|
||||
if ( arg.loc ) {
|
||||
arg.loc->Describe(d);
|
||||
}
|
||||
else {
|
||||
d->Add("<no location>");
|
||||
}
|
||||
break;
|
||||
|
||||
case INPUT_FILE: {
|
||||
d->Add("(");
|
||||
d->Add(input_file.first);
|
||||
d->Add(", ");
|
||||
if ( input_file.second )
|
||||
d->Add(input_file.second->substr(0, 20)); // cut content off
|
||||
else
|
||||
d->Add("<no content>");
|
||||
|
||||
d->Add(")");
|
||||
break;
|
||||
}
|
||||
|
||||
case PACKET: d->Add("<packet>"); break;
|
||||
}
|
||||
}
|
||||
|
||||
Plugin::Plugin() {
|
||||
dynamic = false;
|
||||
Manager::RegisterPlugin(this);
|
||||
}
|
||||
|
||||
Plugin::~Plugin() { Done(); }
|
||||
|
||||
void Plugin::DoConfigure() { config = Configure(); }
|
||||
|
||||
const std::string& Plugin::Name() const { return config.name; }
|
||||
|
||||
const std::string& Plugin::Description() const { return config.description; }
|
||||
|
||||
VersionNumber Plugin::Version() const { return config.version; }
|
||||
|
||||
bool Plugin::DynamicPlugin() const { return dynamic; }
|
||||
|
||||
const std::string& Plugin::PluginDirectory() const { return base_dir; }
|
||||
|
||||
const std::string& Plugin::PluginPath() const { return sopath; }
|
||||
|
||||
void Plugin::SetPluginLocation(const std::string& arg_dir, const std::string& arg_sopath) {
|
||||
base_dir = arg_dir;
|
||||
sopath = arg_sopath;
|
||||
}
|
||||
|
||||
void Plugin::SetDynamic(bool is_dynamic) { dynamic = is_dynamic; }
|
||||
|
||||
void Plugin::InitPreScript() {}
|
||||
|
||||
void Plugin::InitPostScript() {}
|
||||
|
||||
Plugin::bif_item_list Plugin::BifItems() const { return bif_items; }
|
||||
|
||||
void Plugin::Done() {
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
|
||||
delete *i;
|
||||
|
||||
components.clear();
|
||||
}
|
||||
|
||||
Plugin::component_list Plugin::Components() const { return components; }
|
||||
|
||||
static bool component_cmp(const Component* a, const Component* b) { return a->Name() < b->Name(); }
|
||||
|
||||
bool Plugin::LoadZeekFile(const std::string& file) {
|
||||
::add_input_file(file.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Plugin::AddBifItem(const std::string& name, BifItem::Type type) {
|
||||
BifItem bi(name, (BifItem::Type)type);
|
||||
bif_items.push_back(bi);
|
||||
}
|
||||
|
||||
void Plugin::AddComponent(Component* c) {
|
||||
components.push_back(c);
|
||||
|
||||
// Sort components by name to make sure we have a deterministic
|
||||
// order.
|
||||
components.sort(component_cmp);
|
||||
}
|
||||
|
||||
Plugin::hook_list Plugin::EnabledHooks() const { return plugin_mgr->HooksEnabledForPlugin(this); }
|
||||
|
||||
void Plugin::EnableHook(HookType hook, int priority) { plugin_mgr->EnableHook(hook, this, priority); }
|
||||
|
||||
void Plugin::DisableHook(HookType hook) { plugin_mgr->DisableHook(hook, this); }
|
||||
|
||||
void Plugin::RequestEvent(EventHandlerPtr handler) { plugin_mgr->RequestEvent(handler, this); }
|
||||
|
||||
void Plugin::RequestObjDtor(Obj* obj) { plugin_mgr->RequestObjDtor(obj, this); }
|
||||
|
||||
int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std::string& resolved) { return -1; }
|
||||
|
||||
std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const LoadType type, const std::string& file,
|
||||
const std::string& resolved) {
|
||||
return std::make_pair(-1, std::nullopt);
|
||||
}
|
||||
|
||||
std::pair<bool, ValPtr> Plugin::HookFunctionCall(const Func* func, zeek::detail::Frame* parent, Args* args) {
|
||||
return {false, nullptr};
|
||||
}
|
||||
|
||||
bool Plugin::HookQueueEvent(Event* event) { return false; }
|
||||
|
||||
void Plugin::HookDrainEvents() {}
|
||||
|
||||
void Plugin::HookUpdateNetworkTime(double network_time) {}
|
||||
|
||||
void Plugin::HookSetupAnalyzerTree(Connection* conn) {}
|
||||
|
||||
void Plugin::HookObjDtor(void* obj) {}
|
||||
|
||||
void Plugin::HookLogInit(const std::string& writer, const std::string& instantiating_filter, bool local, bool remote,
|
||||
const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields) {}
|
||||
|
||||
bool Plugin::HookLogWrite(const std::string& writer, const std::string& filter,
|
||||
const logging::WriterBackend::WriterInfo& info, int num_fields,
|
||||
const threading::Field* const* fields, threading::Value** vals)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
const threading::Field* const* fields, threading::Value** vals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event,
|
||||
const Connection* conn, const ValPList* addl, bool location,
|
||||
const zeek::detail::Location* location1,
|
||||
const zeek::detail::Location* location2, bool time,
|
||||
const std::string& message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event, const Connection* conn,
|
||||
const ValPList* addl, bool location, const zeek::detail::Location* location1,
|
||||
const zeek::detail::Location* location2, bool time, const std::string& message) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Plugin::HookUnprocessedPacket(const Packet* packet) { }
|
||||
void Plugin::HookUnprocessedPacket(const Packet* packet) {}
|
||||
|
||||
void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) { }
|
||||
void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) {}
|
||||
|
||||
void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) { }
|
||||
void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) {}
|
||||
|
||||
void Plugin::InitializeComponents()
|
||||
{
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
|
||||
(*i)->Initialize();
|
||||
}
|
||||
void Plugin::InitializeComponents() {
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
|
||||
(*i)->Initialize();
|
||||
}
|
||||
|
||||
void Plugin::Describe(ODesc* d) const
|
||||
{
|
||||
d->Add(config.name);
|
||||
void Plugin::Describe(ODesc* d) const {
|
||||
d->Add(config.name);
|
||||
|
||||
if ( config.description.size() )
|
||||
{
|
||||
d->Add(" - ");
|
||||
d->Add(config.description);
|
||||
}
|
||||
if ( config.description.size() ) {
|
||||
d->Add(" - ");
|
||||
d->Add(config.description);
|
||||
}
|
||||
|
||||
if ( dynamic )
|
||||
{
|
||||
d->Add(" (dynamic, ");
|
||||
if ( dynamic ) {
|
||||
d->Add(" (dynamic, ");
|
||||
|
||||
if ( config.version )
|
||||
{
|
||||
d->Add("version ");
|
||||
d->Add(config.version.major);
|
||||
d->Add(".");
|
||||
d->Add(config.version.minor);
|
||||
d->Add(".");
|
||||
d->Add(config.version.patch);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("no version information)");
|
||||
}
|
||||
if ( config.version ) {
|
||||
d->Add("version ");
|
||||
d->Add(config.version.major);
|
||||
d->Add(".");
|
||||
d->Add(config.version.minor);
|
||||
d->Add(".");
|
||||
d->Add(config.version.patch);
|
||||
d->Add(")");
|
||||
}
|
||||
else
|
||||
d->Add("no version information)");
|
||||
}
|
||||
|
||||
else
|
||||
d->Add(" (built-in)");
|
||||
else
|
||||
d->Add(" (built-in)");
|
||||
|
||||
d->Add("\n");
|
||||
d->Add("\n");
|
||||
|
||||
if ( d->IsShort() )
|
||||
return;
|
||||
if ( d->IsShort() )
|
||||
return;
|
||||
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ )
|
||||
{
|
||||
(*i)->Describe(d);
|
||||
d->Add("\n");
|
||||
}
|
||||
for ( component_list::const_iterator i = components.begin(); i != components.end(); i++ ) {
|
||||
(*i)->Describe(d);
|
||||
d->Add("\n");
|
||||
}
|
||||
|
||||
bif_item_list items = BifItems();
|
||||
bif_item_list items = BifItems();
|
||||
|
||||
for ( bif_item_list::const_iterator i = items.begin(); i != items.end(); i++ )
|
||||
{
|
||||
const char* type = nullptr;
|
||||
for ( bif_item_list::const_iterator i = items.begin(); i != items.end(); i++ ) {
|
||||
const char* type = nullptr;
|
||||
|
||||
switch ( (*i).GetType() )
|
||||
{
|
||||
case BifItem::FUNCTION:
|
||||
type = "Function";
|
||||
break;
|
||||
switch ( (*i).GetType() ) {
|
||||
case BifItem::FUNCTION: type = "Function"; break;
|
||||
|
||||
case BifItem::EVENT:
|
||||
type = "Event";
|
||||
break;
|
||||
case BifItem::EVENT: type = "Event"; break;
|
||||
|
||||
case BifItem::CONSTANT:
|
||||
type = "Constant";
|
||||
break;
|
||||
case BifItem::CONSTANT: type = "Constant"; break;
|
||||
|
||||
case BifItem::GLOBAL:
|
||||
type = "Global";
|
||||
break;
|
||||
case BifItem::GLOBAL: type = "Global"; break;
|
||||
|
||||
case BifItem::TYPE:
|
||||
type = "Type";
|
||||
break;
|
||||
case BifItem::TYPE: type = "Type"; break;
|
||||
|
||||
default:
|
||||
type = "<unknown>";
|
||||
}
|
||||
default: type = "<unknown>";
|
||||
}
|
||||
|
||||
d->Add(" ");
|
||||
d->Add("[");
|
||||
d->Add(type);
|
||||
d->Add("] ");
|
||||
d->Add((*i).GetID());
|
||||
d->Add("\n");
|
||||
}
|
||||
d->Add(" ");
|
||||
d->Add("[");
|
||||
d->Add(type);
|
||||
d->Add("] ");
|
||||
d->Add((*i).GetID());
|
||||
d->Add("\n");
|
||||
}
|
||||
|
||||
hook_list hooks = EnabledHooks();
|
||||
hook_list hooks = EnabledHooks();
|
||||
|
||||
for ( hook_list::iterator i = hooks.begin(); i != hooks.end(); i++ )
|
||||
{
|
||||
HookType hook = (*i).first;
|
||||
int prio = (*i).second;
|
||||
for ( hook_list::iterator i = hooks.begin(); i != hooks.end(); i++ ) {
|
||||
HookType hook = (*i).first;
|
||||
int prio = (*i).second;
|
||||
|
||||
d->Add(" Implements ");
|
||||
d->Add(hook_name(hook));
|
||||
d->Add(" (priority ");
|
||||
d->Add(prio);
|
||||
d->Add(")\n");
|
||||
}
|
||||
}
|
||||
d->Add(" Implements ");
|
||||
d->Add(hook_name(hook));
|
||||
d->Add(" (priority ");
|
||||
d->Add(prio);
|
||||
d->Add(")\n");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace zeek::plugin
|
||||
} // namespace zeek::plugin
|
||||
|
|
1860
src/plugin/Plugin.h
1860
src/plugin/Plugin.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue