mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Move all of the base plugin classes into the zeek::plugin namespace
This commit is contained in:
parent
cbdb8ee074
commit
e77e8c4b7b
28 changed files with 404 additions and 240 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 7d474ff6ac0ff1870eef6159bef93a1bfed953df
|
Subproject commit b1526de0d4b8639b51b79b712e83ea62597df1c0
|
|
@ -37,7 +37,7 @@ Attr::Attr(attr_tag t)
|
||||||
|
|
||||||
Attr::~Attr() = default;
|
Attr::~Attr() = default;
|
||||||
|
|
||||||
void Attr::SetAttrExpr(IntrusivePtr<Expr> e)
|
void Attr::SetAttrExpr(IntrusivePtr<zeek::detail::Expr> e)
|
||||||
{ expr = std::move(e); }
|
{ expr = std::move(e); }
|
||||||
|
|
||||||
void Attr::Describe(ODesc* d) const
|
void Attr::Describe(ODesc* d) const
|
||||||
|
|
|
@ -45,7 +45,7 @@ enum DebugStream {
|
||||||
|
|
||||||
#define PLUGIN_DBG_LOG(plugin, args...) debug_logger.Log(plugin, args)
|
#define PLUGIN_DBG_LOG(plugin, args...) debug_logger.Log(plugin, args)
|
||||||
|
|
||||||
namespace plugin { class Plugin; }
|
namespace zeek::plugin { class Plugin; }
|
||||||
|
|
||||||
class DebugLogger {
|
class DebugLogger {
|
||||||
public:
|
public:
|
||||||
|
@ -56,7 +56,7 @@ public:
|
||||||
void OpenDebugLog(const char* filename = 0);
|
void OpenDebugLog(const char* filename = 0);
|
||||||
|
|
||||||
void Log(DebugStream stream, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
|
void Log(DebugStream stream, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||||
void Log(const plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
|
void Log(const zeek::plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
void PushIndent(DebugStream stream)
|
void PushIndent(DebugStream stream)
|
||||||
{ ++streams[int(stream)].indent; }
|
{ ++streams[int(stream)].indent; }
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
using namespace analyzer;
|
using namespace analyzer;
|
||||||
|
|
||||||
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial)
|
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial)
|
||||||
: plugin::Component(plugin::component::ANALYZER, name),
|
: zeek::plugin::Component(zeek::plugin::component::ANALYZER, name),
|
||||||
plugin::TaggedComponent<analyzer::Tag>(arg_subtype)
|
plugin::TaggedComponent<analyzer::Tag>(arg_subtype)
|
||||||
{
|
{
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Analyzer;
|
||||||
* A plugin can provide a specific protocol analyzer by registering this
|
* A plugin can provide a specific protocol analyzer by registering this
|
||||||
* analyzer component, describing the analyzer.
|
* analyzer component, describing the analyzer.
|
||||||
*/
|
*/
|
||||||
class Component : public plugin::Component,
|
class Component : public zeek::plugin::Component,
|
||||||
public plugin::TaggedComponent<analyzer::Tag> {
|
public plugin::TaggedComponent<analyzer::Tag> {
|
||||||
public:
|
public:
|
||||||
typedef Analyzer* (*factory_callback)(Connection* conn);
|
typedef Analyzer* (*factory_callback)(Connection* conn);
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
class EnumVal;
|
class EnumVal;
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
template <class T> class TaggedComponent;
|
||||||
|
template <class T, class C> class ComponentManager;
|
||||||
|
}
|
||||||
namespace plugin {
|
namespace plugin {
|
||||||
template <class T>
|
template <class T>
|
||||||
class TaggedComponent;
|
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
|
||||||
template <class T, class C>
|
zeek::plugin::TaggedComponent<T>;
|
||||||
class ComponentManager;
|
template <class T, class C>
|
||||||
|
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
|
||||||
|
zeek::plugin::ComponentManager<T, C>;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace analyzer {
|
namespace analyzer {
|
||||||
|
@ -92,8 +98,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class analyzer::Manager;
|
friend class analyzer::Manager;
|
||||||
friend class plugin::ComponentManager<Tag, Component>;
|
friend class zeek::plugin::ComponentManager<Tag, Component>;
|
||||||
friend class plugin::TaggedComponent<Tag>;
|
friend class zeek::plugin::TaggedComponent<Tag>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
using namespace file_analysis;
|
using namespace file_analysis;
|
||||||
|
|
||||||
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t subtype)
|
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t subtype)
|
||||||
: plugin::Component(plugin::component::FILE_ANALYZER, name),
|
: zeek::plugin::Component(zeek::plugin::component::FILE_ANALYZER, name),
|
||||||
plugin::TaggedComponent<file_analysis::Tag>(subtype)
|
plugin::TaggedComponent<file_analysis::Tag>(subtype)
|
||||||
{
|
{
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
|
@ -17,7 +17,7 @@ Component::Component(const std::string& name, factory_callback arg_factory, Tag:
|
||||||
}
|
}
|
||||||
|
|
||||||
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype)
|
Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype)
|
||||||
: plugin::Component(plugin::component::FILE_ANALYZER, name),
|
: zeek::plugin::Component(zeek::plugin::component::FILE_ANALYZER, name),
|
||||||
plugin::TaggedComponent<file_analysis::Tag>(subtype)
|
plugin::TaggedComponent<file_analysis::Tag>(subtype)
|
||||||
{
|
{
|
||||||
factory = nullptr;
|
factory = nullptr;
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Manager;
|
||||||
* A plugin can provide a specific file analyzer by registering this
|
* A plugin can provide a specific file analyzer by registering this
|
||||||
* analyzer component, describing the analyzer.
|
* analyzer component, describing the analyzer.
|
||||||
*/
|
*/
|
||||||
class Component : public plugin::Component,
|
class Component : public zeek::plugin::Component,
|
||||||
public plugin::TaggedComponent<file_analysis::Tag> {
|
public plugin::TaggedComponent<file_analysis::Tag> {
|
||||||
public:
|
public:
|
||||||
typedef Analyzer* (*factory_callback)(RecordVal* args, File* file);
|
typedef Analyzer* (*factory_callback)(RecordVal* args, File* file);
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
class EnumVal;
|
class EnumVal;
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
template <class T> class TaggedComponent;
|
||||||
|
template <class T, class C> class ComponentManager;
|
||||||
|
}
|
||||||
namespace plugin {
|
namespace plugin {
|
||||||
template <class T>
|
template <class T>
|
||||||
class TaggedComponent;
|
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
|
||||||
template <class T, class C>
|
zeek::plugin::TaggedComponent<T>;
|
||||||
class ComponentManager;
|
template <class T, class C>
|
||||||
|
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
|
||||||
|
zeek::plugin::ComponentManager<T, C>;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace file_analysis {
|
namespace file_analysis {
|
||||||
|
@ -90,8 +96,8 @@ public:
|
||||||
static const Tag Error;
|
static const Tag Error;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class plugin::ComponentManager<Tag, Component>;
|
friend class zeek::plugin::ComponentManager<Tag, Component>;
|
||||||
friend class plugin::TaggedComponent<Tag>;
|
friend class zeek::plugin::TaggedComponent<Tag>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
using namespace input;
|
using namespace input;
|
||||||
|
|
||||||
Component::Component(const std::string& name, factory_callback arg_factory)
|
Component::Component(const std::string& name, factory_callback arg_factory)
|
||||||
: plugin::Component(plugin::component::READER, name)
|
: zeek::plugin::Component(zeek::plugin::component::READER, name)
|
||||||
{
|
{
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
}
|
}
|
||||||
|
@ -29,4 +29,3 @@ void Component::DoDescribe(ODesc* d) const
|
||||||
d->Add("Input::READER_");
|
d->Add("Input::READER_");
|
||||||
d->Add(CanonicalName());
|
d->Add(CanonicalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class ReaderBackend;
|
||||||
/**
|
/**
|
||||||
* Component description for plugins providing log readers.
|
* Component description for plugins providing log readers.
|
||||||
*/
|
*/
|
||||||
class Component : public plugin::Component,
|
class Component : public zeek::plugin::Component,
|
||||||
public plugin::TaggedComponent<input::Tag> {
|
public plugin::TaggedComponent<input::Tag> {
|
||||||
public:
|
public:
|
||||||
typedef ReaderBackend* (*factory_callback)(ReaderFrontend* frontend);
|
typedef ReaderBackend* (*factory_callback)(ReaderFrontend* frontend);
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
class EnumVal;
|
class EnumVal;
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
template <class T> class TaggedComponent;
|
||||||
|
template <class T, class C> class ComponentManager;
|
||||||
|
}
|
||||||
namespace plugin {
|
namespace plugin {
|
||||||
template <class T>
|
template <class T>
|
||||||
class TaggedComponent;
|
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
|
||||||
template <class T, class C>
|
zeek::plugin::TaggedComponent<T>;
|
||||||
class ComponentManager;
|
template <class T, class C>
|
||||||
|
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
|
||||||
|
zeek::plugin::ComponentManager<T, C>;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace input {
|
namespace input {
|
||||||
|
@ -91,8 +97,8 @@ public:
|
||||||
static const Tag Error;
|
static const Tag Error;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class plugin::ComponentManager<Tag, Component>;
|
friend class zeek::plugin::ComponentManager<Tag, Component>;
|
||||||
friend class plugin::TaggedComponent<Tag>;
|
friend class zeek::plugin::TaggedComponent<Tag>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
|
@ -8,12 +8,17 @@
|
||||||
using namespace iosource;
|
using namespace iosource;
|
||||||
|
|
||||||
Component::Component(const std::string& name)
|
Component::Component(const std::string& name)
|
||||||
: plugin::Component(plugin::component::IOSOURCE, name)
|
: zeek::plugin::Component(zeek::plugin::component::IOSOURCE, name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Component::Component(zeek::plugin::component::Type type, const std::string& name)
|
||||||
|
: plugin::Component(type, name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Component::Component(plugin::component::Type type, const std::string& name)
|
Component::Component(plugin::component::Type type, const std::string& name)
|
||||||
: plugin::Component(type, name)
|
: plugin::Component(static_cast<zeek::plugin::component::Type>(type), name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +27,7 @@ Component::~Component()
|
||||||
}
|
}
|
||||||
|
|
||||||
PktSrcComponent::PktSrcComponent(const std::string& arg_name, const std::string& arg_prefix, InputType arg_type, factory_callback arg_factory)
|
PktSrcComponent::PktSrcComponent(const std::string& arg_name, const std::string& arg_prefix, InputType arg_type, factory_callback arg_factory)
|
||||||
: iosource::Component(plugin::component::PKTSRC, arg_name)
|
: iosource::Component(zeek::plugin::component::PKTSRC, arg_name)
|
||||||
{
|
{
|
||||||
tokenize_string(arg_prefix, ":", &prefixes);
|
tokenize_string(arg_prefix, ":", &prefixes);
|
||||||
type = arg_type;
|
type = arg_type;
|
||||||
|
@ -108,7 +113,7 @@ void PktSrcComponent::DoDescribe(ODesc* d) const
|
||||||
}
|
}
|
||||||
|
|
||||||
PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory)
|
PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory)
|
||||||
: plugin::Component(plugin::component::PKTDUMPER, name)
|
: zeek::plugin::Component(zeek::plugin::component::PKTDUMPER, name)
|
||||||
{
|
{
|
||||||
tokenize_string(arg_prefix, ":", &prefixes);
|
tokenize_string(arg_prefix, ":", &prefixes);
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
|
@ -142,7 +147,7 @@ bool PktDumperComponent::HandlesPrefix(const std::string& prefix) const
|
||||||
|
|
||||||
void PktDumperComponent::DoDescribe(ODesc* d) const
|
void PktDumperComponent::DoDescribe(ODesc* d) const
|
||||||
{
|
{
|
||||||
plugin::Component::DoDescribe(d);
|
zeek::plugin::Component::DoDescribe(d);
|
||||||
|
|
||||||
std::string prefs;
|
std::string prefs;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class PktDumper;
|
||||||
/**
|
/**
|
||||||
* Component description for plugins providing IOSources.
|
* Component description for plugins providing IOSources.
|
||||||
*/
|
*/
|
||||||
class Component : public plugin::Component {
|
class Component : public zeek::plugin::Component {
|
||||||
public:
|
public:
|
||||||
typedef IOSource* (*factory_callback)();
|
typedef IOSource* (*factory_callback)();
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ public:
|
||||||
~Component() override;
|
~Component() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to use by derived classes.
|
* Constructor to use by derived classes.
|
||||||
*
|
*
|
||||||
|
@ -42,6 +43,17 @@ protected:
|
||||||
* @param name A descriptive name for the component. This name must
|
* @param name A descriptive name for the component. This name must
|
||||||
* be unique across all components of this type.
|
* be unique across all components of this type.
|
||||||
*/
|
*/
|
||||||
|
Component(zeek::plugin::component::Type type, const std::string& name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to use by derived classes.
|
||||||
|
*
|
||||||
|
* @param type The type of the componnent.
|
||||||
|
*
|
||||||
|
* @param name A descriptive name for the component. This name must
|
||||||
|
* be unique across all components of this type.
|
||||||
|
*/
|
||||||
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::component::Type instead")]]
|
||||||
Component(plugin::component::Type type, const std::string& name);
|
Component(plugin::component::Type type, const std::string& name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,7 +138,7 @@ private:
|
||||||
* PktDumpers aren't IOSurces but we locate them here to keep them along with
|
* PktDumpers aren't IOSurces but we locate them here to keep them along with
|
||||||
* the PktSrc.
|
* the PktSrc.
|
||||||
*/
|
*/
|
||||||
class PktDumperComponent : public plugin::Component {
|
class PktDumperComponent : public zeek::plugin::Component {
|
||||||
public:
|
public:
|
||||||
typedef PktDumper* (*factory_callback)(const std::string& path, bool append);
|
typedef PktDumper* (*factory_callback)(const std::string& path, bool append);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
using namespace logging;
|
using namespace logging;
|
||||||
|
|
||||||
Component::Component(const std::string& name, factory_callback arg_factory)
|
Component::Component(const std::string& name, factory_callback arg_factory)
|
||||||
: plugin::Component(plugin::component::WRITER, name)
|
: zeek::plugin::Component(zeek::plugin::component::WRITER, name)
|
||||||
{
|
{
|
||||||
factory = arg_factory;
|
factory = arg_factory;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class WriterBackend;
|
||||||
/**
|
/**
|
||||||
* Component description for plugins providing log writers.
|
* Component description for plugins providing log writers.
|
||||||
*/
|
*/
|
||||||
class Component : public plugin::Component,
|
class Component : public zeek::plugin::Component,
|
||||||
public plugin::TaggedComponent<logging::Tag> {
|
public plugin::TaggedComponent<logging::Tag> {
|
||||||
public:
|
public:
|
||||||
typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend);
|
typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend);
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
class EnumVal;
|
class EnumVal;
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
template <class T> class TaggedComponent;
|
||||||
|
template <class T, class C> class ComponentManager;
|
||||||
|
}
|
||||||
namespace plugin {
|
namespace plugin {
|
||||||
template <class T>
|
template <class T>
|
||||||
class TaggedComponent;
|
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
|
||||||
template <class T, class C>
|
zeek::plugin::TaggedComponent<T>;
|
||||||
class ComponentManager;
|
template <class T, class C>
|
||||||
|
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
|
||||||
|
zeek::plugin::ComponentManager<T, C>;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace logging {
|
namespace logging {
|
||||||
|
@ -96,8 +102,8 @@ public:
|
||||||
static const Tag Error;
|
static const Tag Error;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class plugin::ComponentManager<Tag, Component>;
|
friend class zeek::plugin::ComponentManager<Tag, Component>;
|
||||||
friend class plugin::TaggedComponent<Tag>;
|
friend class zeek::plugin::TaggedComponent<Tag>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "../Desc.h"
|
#include "../Desc.h"
|
||||||
#include "../Reporter.h"
|
#include "../Reporter.h"
|
||||||
|
|
||||||
using namespace plugin;
|
using namespace zeek::plugin;
|
||||||
|
|
||||||
Component::Component(component::Type arg_type, const std::string& arg_name)
|
Component::Component(component::Type arg_type, const std::string& arg_name)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,13 @@ Component::Component(component::Type arg_type, const std::string& arg_name)
|
||||||
canon_name = canonify_name(name);
|
canon_name = canonify_name(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component::Component(::plugin::component::Type arg_type, const std::string& arg_name)
|
||||||
|
{
|
||||||
|
type = static_cast<component::Type>(arg_type);
|
||||||
|
name = arg_name;
|
||||||
|
canon_name = canonify_name(name);
|
||||||
|
}
|
||||||
|
|
||||||
Component::~Component()
|
Component::~Component()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,21 @@
|
||||||
|
|
||||||
class ODesc;
|
class ODesc;
|
||||||
|
|
||||||
namespace plugin {
|
namespace plugin::component {
|
||||||
|
|
||||||
|
enum [[deprecated("Remove in v4.1. Use zeek::plugin::component::Type instead.")]] Type {
|
||||||
|
READER, /// An input reader (not currently used).
|
||||||
|
WRITER, /// A logging writer (not currenly used).
|
||||||
|
ANALYZER, /// A protocol analyzer.
|
||||||
|
FILE_ANALYZER, /// A file analyzer.
|
||||||
|
IOSOURCE, /// An I/O source, excluding packet sources.
|
||||||
|
PKTSRC, /// A packet source.
|
||||||
|
PKTDUMPER /// A packet dumper.
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
|
||||||
namespace component {
|
namespace component {
|
||||||
|
|
||||||
|
@ -22,6 +36,7 @@ enum Type {
|
||||||
PKTSRC, /// A packet source.
|
PKTSRC, /// A packet source.
|
||||||
PKTDUMPER /// A packet dumper.
|
PKTDUMPER /// A packet dumper.
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,6 +57,17 @@ public:
|
||||||
*/
|
*/
|
||||||
Component(component::Type type, const std::string& name);
|
Component(component::Type type, const std::string& name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param type The type of the compoment.
|
||||||
|
*
|
||||||
|
* @param name A descriptive name for the component. This name must
|
||||||
|
* be unique across all components of the same type.
|
||||||
|
*/
|
||||||
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::component::Type instead")]]
|
||||||
|
Component(::plugin::component::Type type, const std::string& name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
|
@ -104,3 +130,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace plugin
|
||||||
|
{
|
||||||
|
using Component [[deprecated("Remove in v4.1. Use zeek::plugin::Component instead.")]] = zeek::plugin::Component;
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "zeekygen/Manager.h"
|
#include "zeekygen/Manager.h"
|
||||||
#include "DebugLogger.h"
|
#include "DebugLogger.h"
|
||||||
|
|
||||||
namespace plugin {
|
namespace zeek::plugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that manages tracking of plugin components (e.g. analyzers) and
|
* A class that manages tracking of plugin components (e.g. analyzers) and
|
||||||
|
@ -267,3 +267,9 @@ void ComponentManager<T, C>::RegisterComponent(C* component,
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace plugin
|
} // namespace plugin
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
template <class T, class C>
|
||||||
|
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
|
||||||
|
zeek::plugin::ComponentManager<T, C>;
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "../input.h"
|
#include "../input.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace plugin;
|
using namespace zeek::plugin;
|
||||||
|
|
||||||
Plugin* Manager::current_plugin = nullptr;
|
Plugin* Manager::current_plugin = nullptr;
|
||||||
const char* Manager::current_dir = nullptr;
|
const char* Manager::current_dir = nullptr;
|
||||||
|
@ -515,28 +515,27 @@ static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
||||||
return a.first > b.first;
|
return a.first > b.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::pair<HookType, int> > Manager::HooksEnabledForPlugin(const Plugin* plugin) const
|
std::list<std::pair<::zeek::plugin::HookType, int> > Manager::HooksEnabledForPlugin(const Plugin* plugin) const
|
||||||
{
|
{
|
||||||
std::list<std::pair<HookType, int> > enabled;
|
std::list<std::pair<zeek::plugin::HookType, int> > enabled;
|
||||||
|
|
||||||
for ( int i = 0; i < NUM_HOOKS; i++ )
|
for ( int i = 0; i < NUM_HOOKS; i++ )
|
||||||
{
|
{
|
||||||
hook_list* l = hooks[i];
|
if ( hook_list* l = hooks[i] )
|
||||||
|
for ( const auto& [hook, hook_plugin] : *l )
|
||||||
if ( ! l )
|
if ( hook_plugin == plugin )
|
||||||
continue;
|
enabled.push_back(std::make_pair(static_cast<zeek::plugin::HookType>(i), hook));
|
||||||
|
|
||||||
for ( hook_list::iterator j = l->begin(); j != l->end(); j++ )
|
|
||||||
{
|
|
||||||
if ( (*j).second == plugin )
|
|
||||||
enabled.push_back(std::make_pair((HookType)i, (*j).first));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::EnableHook(HookType hook, Plugin* plugin, int prio)
|
void Manager::EnableHook(::plugin::HookType hook, Plugin* plugin, int prio)
|
||||||
|
{
|
||||||
|
EnableHook(static_cast<zeek::plugin::HookType>(hook), plugin, prio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::EnableHook(zeek::plugin::HookType hook, Plugin* plugin, int prio)
|
||||||
{
|
{
|
||||||
if ( ! hooks[hook] )
|
if ( ! hooks[hook] )
|
||||||
hooks[hook] = new hook_list;
|
hooks[hook] = new hook_list;
|
||||||
|
@ -554,7 +553,12 @@ void Manager::EnableHook(HookType hook, Plugin* plugin, int prio)
|
||||||
l->sort(hook_cmp);
|
l->sort(hook_cmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::DisableHook(HookType hook, Plugin* plugin)
|
void Manager::DisableHook(::plugin::HookType hook, Plugin* plugin)
|
||||||
|
{
|
||||||
|
DisableHook(static_cast<zeek::plugin::HookType>(hook), plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Manager::DisableHook(zeek::plugin::HookType hook, Plugin* plugin)
|
||||||
{
|
{
|
||||||
hook_list* l = hooks[hook];
|
hook_list* l = hooks[hook];
|
||||||
|
|
||||||
|
@ -593,15 +597,15 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(type));
|
args.push_back(HookArgument(type));
|
||||||
args.push_back(HookArgument(file));
|
args.push_back(HookArgument(file));
|
||||||
args.push_back(HookArgument(resolved));
|
args.push_back(HookArgument(resolved));
|
||||||
MetaHookPre(HOOK_LOAD_FILE, args);
|
MetaHookPre(zeek::plugin::HOOK_LOAD_FILE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_LOAD_FILE];
|
hook_list* l = hooks[zeek::plugin::HOOK_LOAD_FILE];
|
||||||
|
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
|
@ -616,8 +620,8 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_LOAD_FILE, args, HookArgument(rc));
|
MetaHookPost(zeek::plugin::HOOK_LOAD_FILE, args, HookArgument(rc));
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -629,7 +633,7 @@ Manager::HookCallFunction(const Func* func, Frame* parent,
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
val_list vargs;
|
val_list vargs;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
vargs.resize(vecargs->size());
|
vargs.resize(vecargs->size());
|
||||||
|
|
||||||
|
@ -639,10 +643,10 @@ Manager::HookCallFunction(const Func* func, Frame* parent,
|
||||||
args.push_back(HookArgument(func));
|
args.push_back(HookArgument(func));
|
||||||
args.push_back(HookArgument(parent));
|
args.push_back(HookArgument(parent));
|
||||||
args.push_back(HookArgument(&vargs));
|
args.push_back(HookArgument(&vargs));
|
||||||
MetaHookPre(HOOK_CALL_FUNCTION, args);
|
MetaHookPre(zeek::plugin::HOOK_CALL_FUNCTION, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_CALL_FUNCTION];
|
hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION];
|
||||||
|
|
||||||
std::pair<bool, IntrusivePtr<Val>> rval{false, nullptr};
|
std::pair<bool, IntrusivePtr<Val>> rval{false, nullptr};
|
||||||
|
|
||||||
|
@ -659,8 +663,8 @@ Manager::HookCallFunction(const Func* func, Frame* parent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_CALL_FUNCTION, args,
|
MetaHookPost(zeek::plugin::HOOK_CALL_FUNCTION, args,
|
||||||
HookArgument(std::make_pair(rval.first, rval.second.get())));
|
HookArgument(std::make_pair(rval.first, rval.second.get())));
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
|
@ -670,13 +674,13 @@ bool Manager::HookQueueEvent(Event* event) const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(event));
|
args.push_back(HookArgument(event));
|
||||||
MetaHookPre(HOOK_QUEUE_EVENT, args);
|
MetaHookPre(zeek::plugin::HOOK_QUEUE_EVENT, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_QUEUE_EVENT];
|
hook_list* l = hooks[zeek::plugin::HOOK_QUEUE_EVENT];
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
|
@ -692,8 +696,8 @@ bool Manager::HookQueueEvent(Event* event) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_QUEUE_EVENT, args, HookArgument(result));
|
MetaHookPost(zeek::plugin::HOOK_QUEUE_EVENT, args, HookArgument(result));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -702,10 +706,10 @@ void Manager::HookDrainEvents() const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
MetaHookPre(HOOK_DRAIN_EVENTS, args);
|
MetaHookPre(zeek::plugin::HOOK_DRAIN_EVENTS, args);
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_DRAIN_EVENTS];
|
hook_list* l = hooks[zeek::plugin::HOOK_DRAIN_EVENTS];
|
||||||
|
|
||||||
if ( l )
|
if ( l )
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
||||||
|
@ -714,8 +718,8 @@ void Manager::HookDrainEvents() const
|
||||||
p->HookDrainEvents();
|
p->HookDrainEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_DRAIN_EVENTS, args, HookArgument());
|
MetaHookPost(zeek::plugin::HOOK_DRAIN_EVENTS, args, HookArgument());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,13 +727,13 @@ void Manager::HookSetupAnalyzerTree(Connection *conn) const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(conn));
|
args.push_back(HookArgument(conn));
|
||||||
MetaHookPre(HOOK_SETUP_ANALYZER_TREE, args);
|
MetaHookPre(zeek::plugin::HOOK_SETUP_ANALYZER_TREE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list *l = hooks[HOOK_SETUP_ANALYZER_TREE];
|
hook_list *l = hooks[zeek::plugin::HOOK_SETUP_ANALYZER_TREE];
|
||||||
|
|
||||||
if ( l )
|
if ( l )
|
||||||
{
|
{
|
||||||
|
@ -740,9 +744,9 @@ void Manager::HookSetupAnalyzerTree(Connection *conn) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
{
|
{
|
||||||
MetaHookPost(HOOK_SETUP_ANALYZER_TREE, args, HookArgument());
|
MetaHookPost(zeek::plugin::HOOK_SETUP_ANALYZER_TREE, args, HookArgument());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,13 +754,13 @@ void Manager::HookUpdateNetworkTime(double network_time) const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(network_time));
|
args.push_back(HookArgument(network_time));
|
||||||
MetaHookPre(HOOK_UPDATE_NETWORK_TIME, args);
|
MetaHookPre(zeek::plugin::HOOK_UPDATE_NETWORK_TIME, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_UPDATE_NETWORK_TIME];
|
hook_list* l = hooks[zeek::plugin::HOOK_UPDATE_NETWORK_TIME];
|
||||||
|
|
||||||
if ( l )
|
if ( l )
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
||||||
|
@ -765,21 +769,21 @@ void Manager::HookUpdateNetworkTime(double network_time) const
|
||||||
p->HookUpdateNetworkTime(network_time);
|
p->HookUpdateNetworkTime(network_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_UPDATE_NETWORK_TIME, args, HookArgument());
|
MetaHookPost(zeek::plugin::HOOK_UPDATE_NETWORK_TIME, args, HookArgument());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::HookBroObjDtor(void* obj) const
|
void Manager::HookBroObjDtor(void* obj) const
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(obj));
|
args.push_back(HookArgument(obj));
|
||||||
MetaHookPre(HOOK_BRO_OBJ_DTOR, args);
|
MetaHookPre(zeek::plugin::HOOK_BRO_OBJ_DTOR, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_BRO_OBJ_DTOR];
|
hook_list* l = hooks[zeek::plugin::HOOK_BRO_OBJ_DTOR];
|
||||||
|
|
||||||
if ( l )
|
if ( l )
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
||||||
|
@ -788,8 +792,8 @@ void Manager::HookBroObjDtor(void* obj) const
|
||||||
p->HookBroObjDtor(obj);
|
p->HookBroObjDtor(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_BRO_OBJ_DTOR, args, HookArgument());
|
MetaHookPost(zeek::plugin::HOOK_BRO_OBJ_DTOR, args, HookArgument());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::HookLogInit(const std::string& writer,
|
void Manager::HookLogInit(const std::string& writer,
|
||||||
|
@ -801,7 +805,7 @@ void Manager::HookLogInit(const std::string& writer,
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(writer));
|
args.push_back(HookArgument(writer));
|
||||||
args.push_back(HookArgument(instantiating_filter));
|
args.push_back(HookArgument(instantiating_filter));
|
||||||
|
@ -810,10 +814,10 @@ void Manager::HookLogInit(const std::string& writer,
|
||||||
args.push_back(HookArgument(&info));
|
args.push_back(HookArgument(&info));
|
||||||
args.push_back(HookArgument(num_fields));
|
args.push_back(HookArgument(num_fields));
|
||||||
args.push_back(HookArgument(std::make_pair(num_fields, fields)));
|
args.push_back(HookArgument(std::make_pair(num_fields, fields)));
|
||||||
MetaHookPre(HOOK_LOG_INIT, args);
|
MetaHookPre(zeek::plugin::HOOK_LOG_INIT, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_LOG_INIT];
|
hook_list* l = hooks[zeek::plugin::HOOK_LOG_INIT];
|
||||||
|
|
||||||
if ( l )
|
if ( l )
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
||||||
|
@ -823,8 +827,8 @@ void Manager::HookLogInit(const std::string& writer,
|
||||||
num_fields, fields);
|
num_fields, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_LOG_INIT, args, HookArgument());
|
MetaHookPost(zeek::plugin::HOOK_LOG_INIT, args, HookArgument());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::HookLogWrite(const std::string& writer,
|
bool Manager::HookLogWrite(const std::string& writer,
|
||||||
|
@ -836,7 +840,7 @@ bool Manager::HookLogWrite(const std::string& writer,
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(writer));
|
args.push_back(HookArgument(writer));
|
||||||
args.push_back(HookArgument(filter));
|
args.push_back(HookArgument(filter));
|
||||||
|
@ -844,10 +848,10 @@ bool Manager::HookLogWrite(const std::string& writer,
|
||||||
args.push_back(HookArgument(num_fields));
|
args.push_back(HookArgument(num_fields));
|
||||||
args.push_back(HookArgument(std::make_pair(num_fields, fields)));
|
args.push_back(HookArgument(std::make_pair(num_fields, fields)));
|
||||||
args.push_back(HookArgument(vals));
|
args.push_back(HookArgument(vals));
|
||||||
MetaHookPre(HOOK_LOG_WRITE, args);
|
MetaHookPre(zeek::plugin::HOOK_LOG_WRITE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_LOG_WRITE];
|
hook_list* l = hooks[zeek::plugin::HOOK_LOG_WRITE];
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
|
@ -864,8 +868,8 @@ bool Manager::HookLogWrite(const std::string& writer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_LOG_WRITE, args, HookArgument(result));
|
MetaHookPost(zeek::plugin::HOOK_LOG_WRITE, args, HookArgument(result));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -878,7 +882,7 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even
|
||||||
{
|
{
|
||||||
HookArgumentList args;
|
HookArgumentList args;
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_PRE) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) )
|
||||||
{
|
{
|
||||||
args.push_back(HookArgument(prefix));
|
args.push_back(HookArgument(prefix));
|
||||||
args.push_back(HookArgument(conn));
|
args.push_back(HookArgument(conn));
|
||||||
|
@ -888,10 +892,10 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even
|
||||||
args.push_back(HookArgument(location));
|
args.push_back(HookArgument(location));
|
||||||
args.push_back(HookArgument(time));
|
args.push_back(HookArgument(time));
|
||||||
args.push_back(HookArgument(message));
|
args.push_back(HookArgument(message));
|
||||||
MetaHookPre(HOOK_REPORTER, args);
|
MetaHookPre(zeek::plugin::HOOK_REPORTER, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_list* l = hooks[HOOK_REPORTER];
|
hook_list* l = hooks[zeek::plugin::HOOK_REPORTER];
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
|
@ -909,33 +913,23 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( HavePluginForHook(META_HOOK_POST) )
|
if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) )
|
||||||
MetaHookPost(HOOK_REPORTER, args, HookArgument(result));
|
MetaHookPost(zeek::plugin::HOOK_REPORTER, args, HookArgument(result));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Manager::MetaHookPre(HookType hook, const HookArgumentList& args) const
|
void Manager::MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) const
|
||||||
{
|
{
|
||||||
hook_list* l = hooks[HOOK_CALL_FUNCTION];
|
if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] )
|
||||||
|
for ( const auto& [hook_type, plugin] : *l )
|
||||||
if ( l )
|
plugin->MetaHookPre(hook, args);
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
|
||||||
{
|
|
||||||
Plugin* p = (*i).second;
|
|
||||||
p->MetaHookPre(hook, args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) const
|
void Manager::MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) const
|
||||||
{
|
{
|
||||||
hook_list* l = hooks[HOOK_CALL_FUNCTION];
|
if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] )
|
||||||
|
for ( const auto& [hook_type, plugin] : *l )
|
||||||
if ( l )
|
plugin->MetaHookPost(hook, args, result);
|
||||||
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
|
|
||||||
{
|
|
||||||
Plugin* p = (*i).second;
|
|
||||||
p->MetaHookPost(hook, args, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "../Reporter.h"
|
#include "../Reporter.h"
|
||||||
#include "../ZeekArgs.h"
|
#include "../ZeekArgs.h"
|
||||||
|
|
||||||
namespace plugin {
|
namespace zeek::plugin {
|
||||||
|
|
||||||
// Macros that trigger plugin hooks. We put this into macros to short-cut the
|
// 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.
|
// code for the most common case that no plugin defines the hook.
|
||||||
|
@ -25,7 +25,7 @@ namespace plugin {
|
||||||
* @param method_call The \a Manager method corresponding to the hook.
|
* @param method_call The \a Manager method corresponding to the hook.
|
||||||
*/
|
*/
|
||||||
#define PLUGIN_HOOK_VOID(hook, method_call) \
|
#define PLUGIN_HOOK_VOID(hook, method_call) \
|
||||||
{ if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call; }
|
{ if ( plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) plugin_mgr->method_call; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Macro to trigger hooks that return a result.
|
* Macro to trigger hooks that return a result.
|
||||||
|
@ -38,7 +38,7 @@ namespace plugin {
|
||||||
* the hook.
|
* the hook.
|
||||||
*/
|
*/
|
||||||
#define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \
|
#define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \
|
||||||
(plugin_mgr->HavePluginForHook(::plugin::hook) ? plugin_mgr->method_call : (default_result))
|
(plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? plugin_mgr->method_call : (default_result))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton object managing all plugins.
|
* A singleton object managing all plugins.
|
||||||
|
@ -47,9 +47,9 @@ class Manager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef void (*bif_init_func)(Plugin *);
|
typedef void (*bif_init_func)(Plugin *);
|
||||||
typedef std::list<Plugin*> plugin_list;
|
using plugin_list = std::list<Plugin*>;
|
||||||
typedef Plugin::component_list component_list;
|
using component_list = Plugin::component_list;
|
||||||
typedef std::list<std::pair<std::string, std::string> > inactive_plugin_list;
|
using inactive_plugin_list = std::list<std::pair<std::string, std::string>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -165,19 +165,26 @@ public:
|
||||||
*
|
*
|
||||||
* @return True if there's a plugin for that hook.
|
* @return True if there's a plugin for that hook.
|
||||||
*/
|
*/
|
||||||
bool HavePluginForHook(HookType hook) const
|
bool HavePluginForHook(zeek::plugin::HookType hook) const
|
||||||
{
|
{
|
||||||
// Inline to avoid the function call.
|
// Inline to avoid the function call.
|
||||||
return hooks[hook] != nullptr;
|
return hooks[hook] != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]]
|
||||||
|
bool HavePluginForHook(::plugin::HookType hook) const
|
||||||
|
{
|
||||||
|
// Inline to avoid the function call.
|
||||||
|
return HavePluginForHook(static_cast<zeek::plugin::HookType>(hook));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the hooks, with their priorities, that are currently
|
* Returns all the hooks, with their priorities, that are currently
|
||||||
* enabled for a given plugin.
|
* enabled for a given plugin.
|
||||||
*
|
*
|
||||||
* @param plugin The plugin to return the hooks for.
|
* @param plugin The plugin to return the hooks for.
|
||||||
*/
|
*/
|
||||||
std::list<std::pair<HookType, int> > HooksEnabledForPlugin(const Plugin* plugin) const;
|
std::list<std::pair<zeek::plugin::HookType, int> > HooksEnabledForPlugin(const Plugin* plugin) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables a hook for a given plugin.
|
* Enables a hook for a given plugin.
|
||||||
|
@ -188,7 +195,9 @@ public:
|
||||||
*
|
*
|
||||||
* prio: The priority to associate with the plugin for this hook.
|
* prio: The priority to associate with the plugin for this hook.
|
||||||
*/
|
*/
|
||||||
void EnableHook(HookType hook, Plugin* plugin, int prio);
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]]
|
||||||
|
void EnableHook(::plugin::HookType hook, Plugin* plugin, int prio);
|
||||||
|
void EnableHook(::zeek::plugin::HookType hook, Plugin* plugin, int prio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables a hook for a given plugin.
|
* Disables a hook for a given plugin.
|
||||||
|
@ -197,7 +206,9 @@ public:
|
||||||
*
|
*
|
||||||
* plugin: The plugin that used to define the hook.
|
* plugin: The plugin that used to define the hook.
|
||||||
*/
|
*/
|
||||||
void DisableHook(HookType hook, Plugin* plugin);
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]]
|
||||||
|
void DisableHook(::plugin::HookType hook, Plugin* plugin);
|
||||||
|
void DisableHook(::zeek::plugin::HookType hook, Plugin* plugin);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers interest in an event by a plugin, even if there's no handler
|
* Registers interest in an event by a plugin, even if there's no handler
|
||||||
|
@ -415,23 +426,23 @@ public:
|
||||||
private:
|
private:
|
||||||
bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found = false);
|
bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found = false);
|
||||||
void UpdateInputFiles();
|
void UpdateInputFiles();
|
||||||
void MetaHookPre(HookType hook, const HookArgumentList& args) const;
|
void MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) const;
|
||||||
void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) const;
|
void MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) const;
|
||||||
|
|
||||||
// All found dynamic plugins, mapping their names to base directory.
|
// All found dynamic plugins, mapping their names to base directory.
|
||||||
typedef std::map<std::string, std::string> dynamic_plugin_map;
|
using dynamic_plugin_map = std::map<std::string, std::string>;
|
||||||
dynamic_plugin_map dynamic_plugins;
|
dynamic_plugin_map dynamic_plugins;
|
||||||
|
|
||||||
// We temporarliy buffer scripts to load to get them to load in the
|
// We temporarliy buffer scripts to load to get them to load in the
|
||||||
// right order.
|
// right order.
|
||||||
typedef std::list<std::string> file_list;
|
using file_list = std::list<std::string>;
|
||||||
file_list scripts_to_load;
|
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
|
// A hook list keeps pairs of plugin and priority interested in a
|
||||||
// given hook.
|
// given hook.
|
||||||
typedef std::list<std::pair<int, Plugin*> > hook_list;
|
using hook_list = std::list<std::pair<int, Plugin*>>;
|
||||||
|
|
||||||
// An array indexed by HookType. An entry is null if there's no hook
|
// An array indexed by HookType. An entry is null if there's no hook
|
||||||
// of that type enabled.
|
// of that type enabled.
|
||||||
|
@ -450,8 +461,8 @@ private:
|
||||||
// even before the manager exists.
|
// even before the manager exists.
|
||||||
static plugin_list* ActivePluginsInternal();
|
static plugin_list* ActivePluginsInternal();
|
||||||
|
|
||||||
typedef std::list<bif_init_func> bif_init_func_list;
|
using bif_init_func_list = std::list<bif_init_func>;
|
||||||
typedef std::map<std::string, bif_init_func_list*> bif_init_func_map;
|
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
|
// Returns a modifiable map of all bif files. This is a static method
|
||||||
// so that plugins can register their bifs even before the manager
|
// so that plugins can register their bifs even before the manager
|
||||||
|
@ -480,20 +491,29 @@ std::list<T *> Manager::Components() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOOD: should this just be zeek::detail?
|
||||||
|
namespace zeek::detail::plugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class used by bifcl-generated code to register its init functions at runtime.
|
* Internal class used by bifcl-generated code to register its init functions at runtime.
|
||||||
*/
|
*/
|
||||||
class __RegisterBif {
|
class __RegisterBif {
|
||||||
public:
|
public:
|
||||||
__RegisterBif(const char* plugin, Manager::bif_init_func init)
|
__RegisterBif(const char* plugin, zeek::plugin::Manager::bif_init_func init)
|
||||||
{
|
{
|
||||||
Manager::RegisterBifFile(plugin, init);
|
zeek::plugin::Manager::RegisterBifFile(plugin, init);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
using Manager [[deprecated("Remove in v4.1. Use zeek::plugin::Manager instead.")]] = zeek::plugin::Manager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global plugin manager singleton.
|
* The global plugin manager singleton.
|
||||||
*/
|
*/
|
||||||
extern plugin::Manager* plugin_mgr;
|
extern zeek::plugin::Manager* plugin_mgr;
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
#include "../input.h"
|
#include "../input.h"
|
||||||
#include "threading/SerialTypes.h"
|
#include "threading/SerialTypes.h"
|
||||||
|
|
||||||
using namespace plugin;
|
using namespace zeek::plugin;
|
||||||
|
|
||||||
const char* plugin::hook_name(HookType h)
|
const char* ::zeek::plugin::hook_name(::zeek::plugin::HookType h)
|
||||||
{
|
{
|
||||||
static const char* hook_names[int(NUM_HOOKS) + 1] = {
|
static constexpr const char* hook_names[int(::zeek::plugin::NUM_HOOKS) + 1] = {
|
||||||
// Order must match that of HookType.
|
// Order must match that of HookType.
|
||||||
"LoadFile",
|
"LoadFile",
|
||||||
"CallFunction",
|
"CallFunction",
|
||||||
|
@ -42,6 +42,11 @@ const char* plugin::hook_name(HookType h)
|
||||||
return hook_names[int(h)];
|
return hook_names[int(h)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* plugin::hook_name(::plugin::HookType h)
|
||||||
|
{
|
||||||
|
return hook_name(static_cast<::zeek::plugin::HookType>(h));
|
||||||
|
}
|
||||||
|
|
||||||
BifItem::BifItem(const std::string& arg_id, Type arg_type)
|
BifItem::BifItem(const std::string& arg_id, Type arg_type)
|
||||||
{
|
{
|
||||||
id = arg_id;
|
id = arg_id;
|
||||||
|
@ -319,7 +324,7 @@ Plugin::component_list Plugin::Components() const
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool component_cmp(const Component* a, const Component* b)
|
static bool component_cmp(const zeek::plugin::Component* a, const zeek::plugin::Component* b)
|
||||||
{
|
{
|
||||||
return a->Name() < b->Name();
|
return a->Name() < b->Name();
|
||||||
}
|
}
|
||||||
|
@ -336,7 +341,7 @@ void Plugin::AddBifItem(const std::string& name, BifItem::Type type)
|
||||||
bif_items.push_back(bi);
|
bif_items.push_back(bi);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::AddComponent(Component* c)
|
void Plugin::AddComponent(zeek::plugin::Component* c)
|
||||||
{
|
{
|
||||||
components.push_back(c);
|
components.push_back(c);
|
||||||
|
|
||||||
|
@ -350,12 +355,22 @@ Plugin::hook_list Plugin::EnabledHooks() const
|
||||||
return plugin_mgr->HooksEnabledForPlugin(this);
|
return plugin_mgr->HooksEnabledForPlugin(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::EnableHook(HookType hook, int priority)
|
void Plugin::EnableHook(::plugin::HookType hook, int priority)
|
||||||
|
{
|
||||||
|
plugin_mgr->EnableHook(static_cast<zeek::plugin::HookType>(hook), this, priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::EnableHook(::zeek::plugin::HookType hook, int priority)
|
||||||
{
|
{
|
||||||
plugin_mgr->EnableHook(hook, this, priority);
|
plugin_mgr->EnableHook(hook, this, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::DisableHook(HookType hook)
|
void Plugin::DisableHook(::plugin::HookType hook)
|
||||||
|
{
|
||||||
|
plugin_mgr->DisableHook(static_cast<zeek::plugin::HookType>(hook), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::DisableHook(::zeek::plugin::HookType hook)
|
||||||
{
|
{
|
||||||
plugin_mgr->DisableHook(hook, this);
|
plugin_mgr->DisableHook(hook, this);
|
||||||
}
|
}
|
||||||
|
@ -446,11 +461,19 @@ bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args)
|
void Plugin::MetaHookPre(::plugin::HookType hook, const HookArgumentList& args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result)
|
void Plugin::MetaHookPost(::plugin::HookType hook, const HookArgumentList& args, HookArgument result)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::MetaHookPre(::zeek::plugin::HookType hook, const HookArgumentList& args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::MetaHookPost(::zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,4 +578,3 @@ void Plugin::Describe(ODesc* d) const
|
||||||
d->Add(")\n");
|
d->Add(")\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,42 @@ namespace threading {
|
||||||
struct Field;
|
struct Field;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace plugin {
|
namespace plugin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook types that a plugin may define. Each label maps to the corresponding
|
||||||
|
* virtual method in \a Plugin.
|
||||||
|
*/
|
||||||
|
enum [[deprecated("Remove in v4.1. Use the zeek::plugin::HookType instead.")]] HookType {
|
||||||
|
// Note: when changing this table, update hook_name() in Plugin.cc.
|
||||||
|
HOOK_LOAD_FILE, //< Activates Plugin::HookLoadFile().
|
||||||
|
HOOK_CALL_FUNCTION, //< Activates Plugin::HookCallFunction().
|
||||||
|
HOOK_QUEUE_EVENT, //< Activates Plugin::HookQueueEvent().
|
||||||
|
HOOK_DRAIN_EVENTS, //< Activates Plugin::HookDrainEvents()
|
||||||
|
HOOK_UPDATE_NETWORK_TIME, //< Activates Plugin::HookUpdateNetworkTime.
|
||||||
|
HOOK_BRO_OBJ_DTOR, //< Activates Plugin::HookBroObjDtor.
|
||||||
|
HOOK_SETUP_ANALYZER_TREE, //< Activates Plugin::HookAddToAnalyzerTree
|
||||||
|
HOOK_LOG_INIT, //< Activates Plugin::HookLogInit
|
||||||
|
HOOK_LOG_WRITE, //< Activates Plugin::HookLogWrite
|
||||||
|
HOOK_REPORTER, //< Activates Plugin::HookReporter
|
||||||
|
|
||||||
|
// Meta hooks.
|
||||||
|
META_HOOK_PRE, //< Activates Plugin::MetaHookPre().
|
||||||
|
META_HOOK_POST, //< Activates Plugin::MetaHookPost().
|
||||||
|
|
||||||
|
// End marker.
|
||||||
|
NUM_HOOKS,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a hook type into a readable hook name.
|
||||||
|
*/
|
||||||
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]]
|
||||||
|
extern const char* hook_name(::plugin::HookType h);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace zeek::plugin {
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
class Component;
|
class Component;
|
||||||
|
@ -60,25 +95,15 @@ enum HookType {
|
||||||
/**
|
/**
|
||||||
* Converts a hook type into a readable hook name.
|
* Converts a hook type into a readable hook name.
|
||||||
*/
|
*/
|
||||||
extern const char* hook_name(HookType h);
|
extern const char* hook_name(::zeek::plugin::HookType h);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to capture a plugin's version.
|
* Helper class to capture a plugin's version.
|
||||||
* */
|
* */
|
||||||
struct VersionNumber {
|
struct VersionNumber {
|
||||||
int major; //< Major version number.
|
int major = -1; //< Major version number.
|
||||||
int minor; //< Minor version number.
|
int minor = -1; //< Minor version number.
|
||||||
int patch; //< Patch version number (available since Zeek 3.0).
|
int patch = 0; //< Patch version number (available since Zeek 3.0).
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
VersionNumber() {
|
|
||||||
// Major and minor versions are required.
|
|
||||||
major = minor = -1;
|
|
||||||
// Patch version is optional, and set to 0 if not manually set.
|
|
||||||
patch = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the version is set to a non-negative value.
|
* Returns true if the version is set to a non-negative value.
|
||||||
|
@ -91,14 +116,17 @@ struct VersionNumber {
|
||||||
*/
|
*/
|
||||||
class Configuration {
|
class Configuration {
|
||||||
public:
|
public:
|
||||||
std::string name; //< The plugin's name, including a namespace. Mandatory.
|
std::string name = ""; //< The plugin's name, including a namespace. Mandatory.
|
||||||
std::string description; //< A short textual description of the plugin. Mandatory.
|
std::string description= ""; //< A short textual description of the plugin. Mandatory.
|
||||||
VersionNumber version; //< THe plugin's version. Optional.
|
VersionNumber version; //< THe plugin's version. Optional.
|
||||||
|
|
||||||
// We force this to inline so that the API version gets hardcoded
|
// We force this to inline so that the API version gets hardcoded
|
||||||
// into the external plugin. (Technically, it's not a "force", just a
|
// into the external plugin. (Technically, it's not a "force", just a
|
||||||
// strong hint.). The attribute seems generally available.
|
// strong hint.). The attribute seems generally available.
|
||||||
inline Configuration() __attribute__((always_inline));
|
inline Configuration() __attribute__((always_inline))
|
||||||
|
{
|
||||||
|
bro_version = BRO_PLUGIN_BRO_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One can assign BRO_PLUGIN_BRO_VERSION to this to catch
|
* One can assign BRO_PLUGIN_BRO_VERSION to this to catch
|
||||||
|
@ -110,13 +138,6 @@ private:
|
||||||
friend class Plugin;
|
friend class Plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Configuration::Configuration()
|
|
||||||
{
|
|
||||||
name = "";
|
|
||||||
description = "";
|
|
||||||
bro_version = BRO_PLUGIN_BRO_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class describing an item defined in \c *.bif file.
|
* A class describing an item defined in \c *.bif file.
|
||||||
*/
|
*/
|
||||||
|
@ -392,7 +413,7 @@ private:
|
||||||
std::string arg_string;
|
std::string arg_string;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<HookArgument> HookArgumentList;
|
using HookArgumentList = std::list<HookArgument>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all plugins.
|
* Base class for all plugins.
|
||||||
|
@ -423,7 +444,7 @@ typedef std::list<HookArgument> HookArgumentList;
|
||||||
*/
|
*/
|
||||||
class Plugin {
|
class Plugin {
|
||||||
public:
|
public:
|
||||||
typedef std::list<Component *> component_list;
|
typedef std::list<zeek::plugin::Component *> component_list;
|
||||||
typedef std::list<BifItem> bif_item_list;
|
typedef std::list<BifItem> bif_item_list;
|
||||||
typedef std::list<std::pair<HookType, int> > hook_list;
|
typedef std::list<std::pair<HookType, int> > hook_list;
|
||||||
|
|
||||||
|
@ -538,7 +559,7 @@ public:
|
||||||
bool LoadBroFile(const std::string& file);
|
bool LoadBroFile(const std::string& file);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Manager;
|
friend class zeek::plugin::Manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First-stage initialization of the plugin called early during Bro's
|
* First-stage initialization of the plugin called early during Bro's
|
||||||
|
@ -568,7 +589,7 @@ protected:
|
||||||
*
|
*
|
||||||
* @param c The component. The method takes ownership.
|
* @param c The component. The method takes ownership.
|
||||||
*/
|
*/
|
||||||
void AddComponent(Component* c);
|
void AddComponent(zeek::plugin::Component* c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the Initialize() function of all components.
|
* Calls the Initialize() function of all components.
|
||||||
|
@ -594,7 +615,9 @@ protected:
|
||||||
* highest to lowest. If two plugins specify the same priority, order
|
* highest to lowest. If two plugins specify the same priority, order
|
||||||
* is undefined.
|
* is undefined.
|
||||||
*/
|
*/
|
||||||
void EnableHook(HookType hook, int priority = 0);
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]]
|
||||||
|
void EnableHook(::plugin::HookType hook, int priority = 0);
|
||||||
|
void EnableHook(zeek::plugin::HookType hook, int priority = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables a hook. Bro will no longer call the corresponding virtual
|
* Disables a hook. Bro will no longer call the corresponding virtual
|
||||||
|
@ -602,7 +625,9 @@ protected:
|
||||||
*
|
*
|
||||||
* @param hook The hook to disable.
|
* @param hook The hook to disable.
|
||||||
*/
|
*/
|
||||||
void DisableHook(HookType hook);
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]]
|
||||||
|
void DisableHook(::plugin::HookType hook);
|
||||||
|
void DisableHook(zeek::plugin::HookType hook);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of hooks that are currently enabled for the plugin,
|
* Returns a list of hooks that are currently enabled for the plugin,
|
||||||
|
@ -855,7 +880,10 @@ protected:
|
||||||
*
|
*
|
||||||
* args: A list of the hooks arguments.
|
* args: A list of the hooks arguments.
|
||||||
*/
|
*/
|
||||||
virtual void MetaHookPre(HookType hook, const HookArgumentList& args);
|
// TODO: unfortunately deprecated virtual methods don't flag when you override them
|
||||||
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]]
|
||||||
|
virtual void MetaHookPre(::plugin::HookType hook, const HookArgumentList& args);
|
||||||
|
virtual void MetaHookPre(::zeek::plugin::HookType hook, const HookArgumentList& args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A meta hook called just after another hook got to execute. This
|
* A meta hook called just after another hook got to execute. This
|
||||||
|
@ -870,7 +898,9 @@ protected:
|
||||||
* implementation for the hook, this will be the default result. If
|
* implementation for the hook, this will be the default result. If
|
||||||
* the hook doesn't yield a result, this will be of type VOID.
|
* the hook doesn't yield a result, this will be of type VOID.
|
||||||
*/
|
*/
|
||||||
virtual void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result);
|
[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]]
|
||||||
|
virtual void MetaHookPost(::plugin::HookType hook, const HookArgumentList& args, HookArgument result);
|
||||||
|
virtual void MetaHookPost(::zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -925,3 +955,12 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
using VersionNumber = zeek::plugin::VersionNumber;
|
||||||
|
using Configuration = zeek::plugin::Configuration;
|
||||||
|
using BifItem = zeek::plugin::BifItem;
|
||||||
|
using HookArgument = zeek::plugin::HookArgument;
|
||||||
|
using HookArgumentList = zeek::plugin::HookArgumentList;
|
||||||
|
using Plugin = zeek::plugin::Plugin;
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace plugin {
|
namespace zeek::plugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which has a tag of a given type associated with it.
|
* A class which has a tag of a given type associated with it.
|
||||||
|
@ -71,3 +71,9 @@ T TaggedComponent<T>::Tag() const
|
||||||
template <class T> typename T::type_t TaggedComponent<T>::type_counter(0);
|
template <class T> typename T::type_t TaggedComponent<T>::type_counter(0);
|
||||||
|
|
||||||
} // namespace plugin
|
} // namespace plugin
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
template <class T>
|
||||||
|
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
|
||||||
|
zeek::plugin::TaggedComponent<T>;
|
||||||
|
}
|
||||||
|
|
|
@ -364,7 +364,7 @@ when return TOK_WHEN;
|
||||||
@load-sigs{WS}{FILE} {
|
@load-sigs{WS}{FILE} {
|
||||||
const char* file = skip_whitespace(yytext + 10);
|
const char* file = skip_whitespace(yytext + 10);
|
||||||
std::string path = find_relative_file(file, ".sig");
|
std::string path = find_relative_file(file, ".sig");
|
||||||
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::SIGNATURES, file, path), -1);
|
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::SIGNATURES, file, path), -1);
|
||||||
|
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -395,7 +395,7 @@ when return TOK_WHEN;
|
||||||
|
|
||||||
@load-plugin{WS}{ID} {
|
@load-plugin{WS}{ID} {
|
||||||
const char* plugin = skip_whitespace(yytext + 12);
|
const char* plugin = skip_whitespace(yytext + 12);
|
||||||
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::PLUGIN, plugin, ""), -1);
|
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::PLUGIN, plugin, ""), -1);
|
||||||
|
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -615,7 +615,7 @@ static bool already_scanned(const std::string& path)
|
||||||
static int load_files(const char* orig_file)
|
static int load_files(const char* orig_file)
|
||||||
{
|
{
|
||||||
std::string file_path = find_relative_script_file(orig_file);
|
std::string file_path = find_relative_script_file(orig_file);
|
||||||
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::SCRIPT, orig_file, file_path), -1);
|
int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::SCRIPT, orig_file, file_path), -1);
|
||||||
|
|
||||||
if ( rc == 1 )
|
if ( rc == 1 )
|
||||||
return 0; // A plugin took care of it, just skip.
|
return 0; // A plugin took care of it, just skip.
|
||||||
|
|
|
@ -91,7 +91,7 @@ ValManager* val_mgr = nullptr;
|
||||||
logging::Manager* log_mgr = nullptr;
|
logging::Manager* log_mgr = nullptr;
|
||||||
threading::Manager* thread_mgr = nullptr;
|
threading::Manager* thread_mgr = nullptr;
|
||||||
input::Manager* input_mgr = nullptr;
|
input::Manager* input_mgr = nullptr;
|
||||||
plugin::Manager* plugin_mgr = nullptr;
|
zeek::plugin::Manager* plugin_mgr = nullptr;
|
||||||
analyzer::Manager* analyzer_mgr = nullptr;
|
analyzer::Manager* analyzer_mgr = nullptr;
|
||||||
file_analysis::Manager* file_mgr = nullptr;
|
file_analysis::Manager* file_mgr = nullptr;
|
||||||
zeekygen::Manager* zeekygen_mgr = nullptr;
|
zeekygen::Manager* zeekygen_mgr = nullptr;
|
||||||
|
@ -160,7 +160,7 @@ static std::vector<const char*> to_cargs(const std::vector<std::string>& args)
|
||||||
|
|
||||||
bool show_plugins(int level)
|
bool show_plugins(int level)
|
||||||
{
|
{
|
||||||
plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
||||||
|
|
||||||
if ( ! plugins.size() )
|
if ( ! plugins.size() )
|
||||||
{
|
{
|
||||||
|
@ -175,7 +175,7 @@ bool show_plugins(int level)
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for ( plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ )
|
for ( zeek::plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ )
|
||||||
{
|
{
|
||||||
if ( requested_plugins.size()
|
if ( requested_plugins.size()
|
||||||
&& requested_plugins.find((*i)->Name()) == requested_plugins.end() )
|
&& requested_plugins.find((*i)->Name()) == requested_plugins.end() )
|
||||||
|
@ -191,13 +191,13 @@ bool show_plugins(int level)
|
||||||
|
|
||||||
printf("%s", d.Description());
|
printf("%s", d.Description());
|
||||||
|
|
||||||
plugin::Manager::inactive_plugin_list inactives = plugin_mgr->InactivePlugins();
|
zeek::plugin::Manager::inactive_plugin_list inactives = plugin_mgr->InactivePlugins();
|
||||||
|
|
||||||
if ( inactives.size() && ! requested_plugins.size() )
|
if ( inactives.size() && ! requested_plugins.size() )
|
||||||
{
|
{
|
||||||
printf("\nInactive dynamic plugins:\n");
|
printf("\nInactive dynamic plugins:\n");
|
||||||
|
|
||||||
for ( plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin(); i != inactives.end(); i++ )
|
for ( zeek::plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin(); i != inactives.end(); i++ )
|
||||||
{
|
{
|
||||||
string name = (*i).first;
|
string name = (*i).first;
|
||||||
string path = (*i).second;
|
string path = (*i).second;
|
||||||
|
@ -467,7 +467,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
||||||
val_mgr = new ValManager();
|
val_mgr = new ValManager();
|
||||||
reporter = new Reporter(options.abort_on_scripting_errors);
|
reporter = new Reporter(options.abort_on_scripting_errors);
|
||||||
thread_mgr = new threading::Manager();
|
thread_mgr = new threading::Manager();
|
||||||
plugin_mgr = new plugin::Manager();
|
plugin_mgr = new zeek::plugin::Manager();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if ( options.debug_log_streams )
|
if ( options.debug_log_streams )
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace zeekygen;
|
using namespace zeekygen;
|
||||||
|
|
||||||
static void write_plugin_section_heading(FILE* f, const plugin::Plugin* p)
|
static void write_plugin_section_heading(FILE* f, const zeek::plugin::Plugin* p)
|
||||||
{
|
{
|
||||||
const string& name = p->Name();
|
const string& name = p->Name();
|
||||||
|
|
||||||
|
@ -55,21 +55,20 @@ static void write_analyzer_component(FILE* f, const file_analysis::Component* c)
|
||||||
fprintf(f, ":zeek:enum:`Files::%s`\n\n", tag.c_str());
|
fprintf(f, ":zeek:enum:`Files::%s`\n\n", tag.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_plugin_components(FILE* f, const plugin::Plugin* p)
|
static void write_plugin_components(FILE* f, const zeek::plugin::Plugin* p)
|
||||||
{
|
{
|
||||||
plugin::Plugin::component_list components = p->Components();
|
zeek::plugin::Plugin::component_list components = p->Components();
|
||||||
plugin::Plugin::component_list::const_iterator it;
|
|
||||||
|
|
||||||
fprintf(f, "Components\n");
|
fprintf(f, "Components\n");
|
||||||
fprintf(f, "++++++++++\n\n");
|
fprintf(f, "++++++++++\n\n");
|
||||||
|
|
||||||
for ( it = components.begin(); it != components.end(); ++it )
|
for ( const auto& component : components )
|
||||||
{
|
{
|
||||||
switch ( (*it)->Type() ) {
|
switch ( component->Type() ) {
|
||||||
case plugin::component::ANALYZER:
|
case zeek::plugin::component::ANALYZER:
|
||||||
{
|
{
|
||||||
const analyzer::Component* c =
|
const analyzer::Component* c =
|
||||||
dynamic_cast<const analyzer::Component*>(*it);
|
dynamic_cast<const analyzer::Component*>(component);
|
||||||
|
|
||||||
if ( c )
|
if ( c )
|
||||||
write_analyzer_component(f, c);
|
write_analyzer_component(f, c);
|
||||||
|
@ -78,10 +77,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case plugin::component::FILE_ANALYZER:
|
case zeek::plugin::component::FILE_ANALYZER:
|
||||||
{
|
{
|
||||||
const file_analysis::Component* c =
|
const file_analysis::Component* c =
|
||||||
dynamic_cast<const file_analysis::Component*>(*it);
|
dynamic_cast<const file_analysis::Component*>(component);
|
||||||
|
|
||||||
if ( c )
|
if ( c )
|
||||||
write_analyzer_component(f, c);
|
write_analyzer_component(f, c);
|
||||||
|
@ -90,10 +89,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case plugin::component::READER:
|
case zeek::plugin::component::READER:
|
||||||
reporter->InternalError("docs for READER component unimplemented");
|
reporter->InternalError("docs for READER component unimplemented");
|
||||||
|
|
||||||
case plugin::component::WRITER:
|
case zeek::plugin::component::WRITER:
|
||||||
reporter->InternalError("docs for WRITER component unimplemented");
|
reporter->InternalError("docs for WRITER component unimplemented");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -102,11 +101,11 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_plugin_bif_items(FILE* f, const plugin::Plugin* p,
|
static void write_plugin_bif_items(FILE* f, const zeek::plugin::Plugin* p,
|
||||||
plugin::BifItem::Type t, const string& heading)
|
zeek::plugin::BifItem::Type t, const string& heading)
|
||||||
{
|
{
|
||||||
plugin::Plugin::bif_item_list bifitems = p->BifItems();
|
zeek::plugin::Plugin::bif_item_list bifitems = p->BifItems();
|
||||||
plugin::Plugin::bif_item_list::iterator it = bifitems.begin();
|
zeek::plugin::Plugin::bif_item_list::iterator it = bifitems.begin();
|
||||||
|
|
||||||
while ( it != bifitems.end() )
|
while ( it != bifitems.end() )
|
||||||
{
|
{
|
||||||
|
@ -150,11 +149,11 @@ static void WriteAnalyzerTagDefn(FILE* f, const string& module)
|
||||||
fprintf(f, "%s\n", doc->ReStructuredText().c_str());
|
fprintf(f, "%s\n", doc->ReStructuredText().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ComponentsMatch(const plugin::Plugin* p, plugin::component::Type t,
|
static bool ComponentsMatch(const zeek::plugin::Plugin* p, zeek::plugin::component::Type t,
|
||||||
bool match_empty = false)
|
bool match_empty = false)
|
||||||
{
|
{
|
||||||
plugin::Plugin::component_list components = p->Components();
|
zeek::plugin::Plugin::component_list components = p->Components();
|
||||||
plugin::Plugin::component_list::const_iterator it;
|
zeek::plugin::Plugin::component_list::const_iterator it;
|
||||||
|
|
||||||
if ( components.empty() )
|
if ( components.empty() )
|
||||||
return match_empty;
|
return match_empty;
|
||||||
|
@ -266,22 +265,22 @@ void ProtoAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const
|
||||||
|
|
||||||
WriteAnalyzerTagDefn(f, "Analyzer");
|
WriteAnalyzerTagDefn(f, "Analyzer");
|
||||||
|
|
||||||
plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
||||||
plugin::Manager::plugin_list::const_iterator it;
|
zeek::plugin::Manager::plugin_list::const_iterator it;
|
||||||
|
|
||||||
for ( it = plugins.begin(); it != plugins.end(); ++it )
|
for ( it = plugins.begin(); it != plugins.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( ! ComponentsMatch(*it, plugin::component::ANALYZER, true) )
|
if ( ! ComponentsMatch(*it, zeek::plugin::component::ANALYZER, true) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
write_plugin_section_heading(f, *it);
|
write_plugin_section_heading(f, *it);
|
||||||
write_plugin_components(f, *it);
|
write_plugin_components(f, *it);
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::CONSTANT,
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::CONSTANT,
|
||||||
"Options/Constants");
|
"Options/Constants");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,22 +291,22 @@ void FileAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const
|
||||||
|
|
||||||
WriteAnalyzerTagDefn(f, "Files");
|
WriteAnalyzerTagDefn(f, "Files");
|
||||||
|
|
||||||
plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins();
|
||||||
plugin::Manager::plugin_list::const_iterator it;
|
zeek::plugin::Manager::plugin_list::const_iterator it;
|
||||||
|
|
||||||
for ( it = plugins.begin(); it != plugins.end(); ++it )
|
for ( it = plugins.begin(); it != plugins.end(); ++it )
|
||||||
{
|
{
|
||||||
if ( ! ComponentsMatch(*it, plugin::component::FILE_ANALYZER) )
|
if ( ! ComponentsMatch(*it, zeek::plugin::component::FILE_ANALYZER) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
write_plugin_section_heading(f, *it);
|
write_plugin_section_heading(f, *it);
|
||||||
write_plugin_components(f, *it);
|
write_plugin_components(f, *it);
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::CONSTANT,
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::CONSTANT,
|
||||||
"Options/Constants");
|
"Options/Constants");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events");
|
||||||
write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions");
|
write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue