diff --git a/aux/bifcl b/aux/bifcl index 7d474ff6ac..b1526de0d4 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 7d474ff6ac0ff1870eef6159bef93a1bfed953df +Subproject commit b1526de0d4b8639b51b79b712e83ea62597df1c0 diff --git a/src/Attr.cc b/src/Attr.cc index f2b854cb50..3920e05fde 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -37,7 +37,7 @@ Attr::Attr(attr_tag t) Attr::~Attr() = default; -void Attr::SetAttrExpr(IntrusivePtr e) +void Attr::SetAttrExpr(IntrusivePtr e) { expr = std::move(e); } void Attr::Describe(ODesc* d) const diff --git a/src/DebugLogger.h b/src/DebugLogger.h index e0eb57f47b..c0caa02088 100644 --- a/src/DebugLogger.h +++ b/src/DebugLogger.h @@ -45,7 +45,7 @@ enum DebugStream { #define PLUGIN_DBG_LOG(plugin, args...) debug_logger.Log(plugin, args) -namespace plugin { class Plugin; } +namespace zeek::plugin { class Plugin; } class DebugLogger { public: @@ -56,7 +56,7 @@ public: void OpenDebugLog(const char* filename = 0); 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) { ++streams[int(stream)].indent; } diff --git a/src/analyzer/Component.cc b/src/analyzer/Component.cc index 2630db84df..99f149ff88 100644 --- a/src/analyzer/Component.cc +++ b/src/analyzer/Component.cc @@ -9,7 +9,7 @@ using namespace analyzer; 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(arg_subtype) { factory = arg_factory; diff --git a/src/analyzer/Component.h b/src/analyzer/Component.h index 1c0f0a2002..bfdb688df3 100644 --- a/src/analyzer/Component.h +++ b/src/analyzer/Component.h @@ -21,7 +21,7 @@ class Analyzer; * A plugin can provide a specific protocol analyzer by registering this * analyzer component, describing the analyzer. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(Connection* conn); diff --git a/src/analyzer/Tag.h b/src/analyzer/Tag.h index 39cdc3ed45..18eaf2fdf6 100644 --- a/src/analyzer/Tag.h +++ b/src/analyzer/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace analyzer { @@ -92,8 +98,8 @@ public: protected: friend class analyzer::Manager; - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/file_analysis/Component.cc b/src/file_analysis/Component.cc index b2a55ce53d..1372a8eedf 100644 --- a/src/file_analysis/Component.cc +++ b/src/file_analysis/Component.cc @@ -9,7 +9,7 @@ using namespace file_analysis; 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(subtype) { 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) - : plugin::Component(plugin::component::FILE_ANALYZER, name), + : zeek::plugin::Component(zeek::plugin::component::FILE_ANALYZER, name), plugin::TaggedComponent(subtype) { factory = nullptr; diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 1bf5efe7ff..98ac262127 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -22,7 +22,7 @@ class Manager; * A plugin can provide a specific file analyzer by registering this * analyzer component, describing the analyzer. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(RecordVal* args, File* file); diff --git a/src/file_analysis/Tag.h b/src/file_analysis/Tag.h index 8c434e20e6..e2a1e1a1d8 100644 --- a/src/file_analysis/Tag.h +++ b/src/file_analysis/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace file_analysis { @@ -90,8 +96,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/input/Component.cc b/src/input/Component.cc index dbca5a2cf3..db6a127b2f 100644 --- a/src/input/Component.cc +++ b/src/input/Component.cc @@ -9,7 +9,7 @@ using namespace input; 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; } @@ -29,4 +29,3 @@ void Component::DoDescribe(ODesc* d) const d->Add("Input::READER_"); d->Add(CanonicalName()); } - diff --git a/src/input/Component.h b/src/input/Component.h index 2e6b55bb96..b9aaa8ec76 100644 --- a/src/input/Component.h +++ b/src/input/Component.h @@ -14,7 +14,7 @@ class ReaderBackend; /** * Component description for plugins providing log readers. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef ReaderBackend* (*factory_callback)(ReaderFrontend* frontend); diff --git a/src/input/Tag.h b/src/input/Tag.h index 20a163da23..b4aa4b11f7 100644 --- a/src/input/Tag.h +++ b/src/input/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace input { @@ -91,8 +97,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/iosource/Component.cc b/src/iosource/Component.cc index 1d8a431df5..c49ec79464 100644 --- a/src/iosource/Component.cc +++ b/src/iosource/Component.cc @@ -8,12 +8,17 @@ using namespace iosource; 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) - : plugin::Component(type, name) + : plugin::Component(static_cast(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) - : iosource::Component(plugin::component::PKTSRC, arg_name) + : iosource::Component(zeek::plugin::component::PKTSRC, arg_name) { tokenize_string(arg_prefix, ":", &prefixes); 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) - : plugin::Component(plugin::component::PKTDUMPER, name) + : zeek::plugin::Component(zeek::plugin::component::PKTDUMPER, name) { tokenize_string(arg_prefix, ":", &prefixes); factory = arg_factory; @@ -142,7 +147,7 @@ bool PktDumperComponent::HandlesPrefix(const std::string& prefix) const void PktDumperComponent::DoDescribe(ODesc* d) const { - plugin::Component::DoDescribe(d); + zeek::plugin::Component::DoDescribe(d); std::string prefs; diff --git a/src/iosource/Component.h b/src/iosource/Component.h index 9d8367ac0a..e3e58b9350 100644 --- a/src/iosource/Component.h +++ b/src/iosource/Component.h @@ -16,7 +16,7 @@ class PktDumper; /** * Component description for plugins providing IOSources. */ -class Component : public plugin::Component { +class Component : public zeek::plugin::Component { public: typedef IOSource* (*factory_callback)(); @@ -34,6 +34,7 @@ public: ~Component() override; protected: + /** * Constructor to use by derived classes. * @@ -42,6 +43,17 @@ protected: * @param name A descriptive name for the component. This name must * 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); }; @@ -126,7 +138,7 @@ private: * PktDumpers aren't IOSurces but we locate them here to keep them along with * the PktSrc. */ -class PktDumperComponent : public plugin::Component { +class PktDumperComponent : public zeek::plugin::Component { public: typedef PktDumper* (*factory_callback)(const std::string& path, bool append); diff --git a/src/logging/Component.cc b/src/logging/Component.cc index 570cccb8d7..b100ce2583 100644 --- a/src/logging/Component.cc +++ b/src/logging/Component.cc @@ -8,7 +8,7 @@ using namespace logging; 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; } diff --git a/src/logging/Component.h b/src/logging/Component.h index b80ae5f0b2..600f6a8438 100644 --- a/src/logging/Component.h +++ b/src/logging/Component.h @@ -14,7 +14,7 @@ class WriterBackend; /** * Component description for plugins providing log writers. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend); diff --git a/src/logging/Tag.h b/src/logging/Tag.h index 78aee1a3d0..01cfb4b04e 100644 --- a/src/logging/Tag.h +++ b/src/logging/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace logging { @@ -96,8 +102,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/plugin/Component.cc b/src/plugin/Component.cc index 4ace2f96af..a37ddca037 100644 --- a/src/plugin/Component.cc +++ b/src/plugin/Component.cc @@ -5,7 +5,7 @@ #include "../Desc.h" #include "../Reporter.h" -using namespace plugin; +using namespace zeek::plugin; 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); } +Component::Component(::plugin::component::Type arg_type, const std::string& arg_name) + { + type = static_cast(arg_type); + name = arg_name; + canon_name = canonify_name(name); + } + Component::~Component() { } diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 4b47481935..b71f20b39b 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -6,7 +6,21 @@ 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 { @@ -22,6 +36,7 @@ enum Type { PKTSRC, /// A packet source. PKTDUMPER /// A packet dumper. }; + } /** @@ -42,6 +57,17 @@ public: */ 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. */ @@ -104,3 +130,8 @@ private: }; } + +namespace plugin + { + using Component [[deprecated("Remove in v4.1. Use zeek::plugin::Component instead.")]] = zeek::plugin::Component; + } diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 3c66fe9dd7..3abb08c8a7 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -13,7 +13,7 @@ #include "zeekygen/Manager.h" #include "DebugLogger.h" -namespace plugin { +namespace zeek::plugin { /** * A class that manages tracking of plugin components (e.g. analyzers) and @@ -267,3 +267,9 @@ void ComponentManager::RegisterComponent(C* component, } } // namespace plugin + +namespace plugin { + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; +} diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 09a3bb5d9f..86fd7be70b 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -19,7 +19,7 @@ #include "../input.h" using namespace std; -using namespace plugin; +using namespace zeek::plugin; Plugin* Manager::current_plugin = nullptr; const char* Manager::current_dir = nullptr; @@ -515,28 +515,27 @@ static bool hook_cmp(std::pair a, std::pair b) return a.first > b.first; } -std::list > Manager::HooksEnabledForPlugin(const Plugin* plugin) const +std::list > Manager::HooksEnabledForPlugin(const Plugin* plugin) const { - std::list > enabled; + std::list > enabled; for ( int i = 0; i < NUM_HOOKS; i++ ) { - hook_list* l = hooks[i]; - - if ( ! l ) - continue; - - 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)); - } + if ( hook_list* l = hooks[i] ) + for ( const auto& [hook, hook_plugin] : *l ) + if ( hook_plugin == plugin ) + enabled.push_back(std::make_pair(static_cast(i), hook)); } return enabled; } -void Manager::EnableHook(HookType hook, Plugin* plugin, int prio) +void Manager::EnableHook(::plugin::HookType hook, Plugin* plugin, int prio) + { + EnableHook(static_cast(hook), plugin, prio); + } + +void Manager::EnableHook(zeek::plugin::HookType hook, Plugin* plugin, int prio) { if ( ! hooks[hook] ) hooks[hook] = new hook_list; @@ -554,7 +553,12 @@ void Manager::EnableHook(HookType hook, Plugin* plugin, int prio) l->sort(hook_cmp); } -void Manager::DisableHook(HookType hook, Plugin* plugin) +void Manager::DisableHook(::plugin::HookType hook, Plugin* plugin) + { + DisableHook(static_cast(hook), plugin); + } + +void Manager::DisableHook(zeek::plugin::HookType hook, Plugin* plugin) { hook_list* l = hooks[hook]; @@ -593,15 +597,15 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(type)); args.push_back(HookArgument(file)); 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; @@ -616,8 +620,8 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const break; } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOAD_FILE, args, HookArgument(rc)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOAD_FILE, args, HookArgument(rc)); return rc; } @@ -629,7 +633,7 @@ Manager::HookCallFunction(const Func* func, Frame* parent, HookArgumentList args; val_list vargs; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { vargs.resize(vecargs->size()); @@ -639,10 +643,10 @@ Manager::HookCallFunction(const Func* func, Frame* parent, args.push_back(HookArgument(func)); args.push_back(HookArgument(parent)); 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> rval{false, nullptr}; @@ -659,8 +663,8 @@ Manager::HookCallFunction(const Func* func, Frame* parent, } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_CALL_FUNCTION, args, + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_CALL_FUNCTION, args, HookArgument(std::make_pair(rval.first, rval.second.get()))); return rval; @@ -670,13 +674,13 @@ bool Manager::HookQueueEvent(Event* event) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { 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; @@ -692,8 +696,8 @@ bool Manager::HookQueueEvent(Event* event) const } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_QUEUE_EVENT, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_QUEUE_EVENT, args, HookArgument(result)); return result; } @@ -702,10 +706,10 @@ void Manager::HookDrainEvents() const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) - MetaHookPre(HOOK_DRAIN_EVENTS, args); + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) + 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 ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -714,8 +718,8 @@ void Manager::HookDrainEvents() const p->HookDrainEvents(); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_DRAIN_EVENTS, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_DRAIN_EVENTS, args, HookArgument()); } @@ -723,13 +727,13 @@ void Manager::HookSetupAnalyzerTree(Connection *conn) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { 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 ) { @@ -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; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { 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 ) 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); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_UPDATE_NETWORK_TIME, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_UPDATE_NETWORK_TIME, args, HookArgument()); } void Manager::HookBroObjDtor(void* obj) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { 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 ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -788,8 +792,8 @@ void Manager::HookBroObjDtor(void* obj) const p->HookBroObjDtor(obj); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_BRO_OBJ_DTOR, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_BRO_OBJ_DTOR, args, HookArgument()); } void Manager::HookLogInit(const std::string& writer, @@ -801,7 +805,7 @@ void Manager::HookLogInit(const std::string& writer, { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(writer)); 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(num_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 ) 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); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOG_INIT, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOG_INIT, args, HookArgument()); } bool Manager::HookLogWrite(const std::string& writer, @@ -836,7 +840,7 @@ bool Manager::HookLogWrite(const std::string& writer, { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(writer)); 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(std::make_pair(num_fields, fields))); 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; @@ -864,8 +868,8 @@ bool Manager::HookLogWrite(const std::string& writer, } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOG_WRITE, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOG_WRITE, args, HookArgument(result)); return result; } @@ -878,7 +882,7 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(prefix)); 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(time)); 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; @@ -909,33 +913,23 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_REPORTER, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_REPORTER, args, HookArgument(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 ( l ) - for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) - { - Plugin* p = (*i).second; - p->MetaHookPre(hook, args); - } + if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] ) + for ( const auto& [hook_type, plugin] : *l ) + plugin->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 ( l ) - for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) - { - Plugin* p = (*i).second; - p->MetaHookPost(hook, args, result); - } + if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] ) + for ( const auto& [hook_type, plugin] : *l ) + plugin->MetaHookPost(hook, args, result); } diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index b3080cf733..2c983b7f31 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -12,7 +12,7 @@ #include "../Reporter.h" #include "../ZeekArgs.h" -namespace plugin { +namespace zeek::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. @@ -25,7 +25,7 @@ namespace plugin { * @param method_call The \a Manager method corresponding to the hook. */ #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. @@ -38,7 +38,7 @@ namespace plugin { * the hook. */ #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. @@ -47,9 +47,9 @@ class Manager { public: typedef void (*bif_init_func)(Plugin *); - typedef std::list plugin_list; - typedef Plugin::component_list component_list; - typedef std::list > inactive_plugin_list; + using plugin_list = std::list; + using component_list = Plugin::component_list; + using inactive_plugin_list = std::list>; /** * Constructor. @@ -165,19 +165,26 @@ public: * * @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. 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(hook)); + } + /** * 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 > HooksEnabledForPlugin(const Plugin* plugin) const; + std::list > HooksEnabledForPlugin(const Plugin* plugin) const; /** * Enables a hook for a given plugin. @@ -188,7 +195,9 @@ public: * * 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. @@ -197,7 +206,9 @@ public: * * 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 @@ -415,23 +426,23 @@ public: private: bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found = false); void UpdateInputFiles(); - void MetaHookPre(HookType hook, const HookArgumentList& args) const; - void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) const; + void MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) const; + void MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) const; // All found dynamic plugins, mapping their names to base directory. - typedef std::map dynamic_plugin_map; + using dynamic_plugin_map = std::map; dynamic_plugin_map dynamic_plugins; // We temporarliy buffer scripts to load to get them to load in the // right order. - typedef std::list file_list; + using file_list = std::list; file_list scripts_to_load; bool init; // Flag indicating whether InitPreScript() has run yet. // A hook list keeps pairs of plugin and priority interested in a // given hook. - typedef std::list > hook_list; + using hook_list = std::list>; // An array indexed by HookType. An entry is null if there's no hook // of that type enabled. @@ -450,8 +461,8 @@ private: // even before the manager exists. static plugin_list* ActivePluginsInternal(); - typedef std::list bif_init_func_list; - typedef std::map bif_init_func_map; + using bif_init_func_list = std::list; + using bif_init_func_map = std::map; // Returns a modifiable map of all bif files. This is a static method // so that plugins can register their bifs even before the manager @@ -480,20 +491,29 @@ std::list Manager::Components() const 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. */ class __RegisterBif { 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. */ -extern plugin::Manager* plugin_mgr; +extern zeek::plugin::Manager* plugin_mgr; diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 262ee2cc64..941ee0038c 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -17,11 +17,11 @@ #include "../input.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. "LoadFile", "CallFunction", @@ -42,6 +42,11 @@ const char* plugin::hook_name(HookType 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) { id = arg_id; @@ -319,7 +324,7 @@ Plugin::component_list Plugin::Components() const 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(); } @@ -336,7 +341,7 @@ void Plugin::AddBifItem(const std::string& name, BifItem::Type type) bif_items.push_back(bi); } -void Plugin::AddComponent(Component* c) +void Plugin::AddComponent(zeek::plugin::Component* c) { components.push_back(c); @@ -350,12 +355,22 @@ Plugin::hook_list Plugin::EnabledHooks() const 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(hook), this, priority); + } + +void Plugin::EnableHook(::zeek::plugin::HookType hook, int priority) { plugin_mgr->EnableHook(hook, this, priority); } -void Plugin::DisableHook(HookType hook) +void Plugin::DisableHook(::plugin::HookType hook) + { + plugin_mgr->DisableHook(static_cast(hook), this); + } + +void Plugin::DisableHook(::zeek::plugin::HookType hook) { plugin_mgr->DisableHook(hook, this); } @@ -446,11 +461,19 @@ bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event 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"); } } - diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 096b796429..e9d5825bc8 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -26,7 +26,42 @@ namespace threading { 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 Component; @@ -60,25 +95,15 @@ enum HookType { /** * 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. * */ struct VersionNumber { - int major; //< Major version number. - int minor; //< Minor version number. - int patch; //< 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; - } + int major = -1; //< Major version number. + int minor = -1; //< Minor version number. + int patch = 0; //< Patch version number (available since Zeek 3.0). /** * Returns true if the version is set to a non-negative value. @@ -91,14 +116,17 @@ struct VersionNumber { */ class Configuration { public: - std::string name; //< The plugin's name, including a namespace. Mandatory. - std::string description; //< A short textual description of the plugin. Mandatory. - VersionNumber version; //< THe plugin's version. Optional. + std::string name = ""; //< The plugin's name, including a namespace. Mandatory. + std::string description= ""; //< A short textual description of the plugin. Mandatory. + VersionNumber version; //< THe plugin's version. Optional. // We force this to inline so that the API version gets hardcoded // into the external plugin. (Technically, it's not a "force", just a // 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 @@ -110,13 +138,6 @@ private: friend class Plugin; }; -inline Configuration::Configuration() - { - name = ""; - description = ""; - bro_version = BRO_PLUGIN_BRO_VERSION; - } - /** * A class describing an item defined in \c *.bif file. */ @@ -392,7 +413,7 @@ private: std::string arg_string; }; -typedef std::list HookArgumentList; +using HookArgumentList = std::list; /** * Base class for all plugins. @@ -423,7 +444,7 @@ typedef std::list HookArgumentList; */ class Plugin { public: - typedef std::list component_list; + typedef std::list component_list; typedef std::list bif_item_list; typedef std::list > hook_list; @@ -538,7 +559,7 @@ public: bool LoadBroFile(const std::string& file); protected: - friend class Manager; + friend class zeek::plugin::Manager; /** * First-stage initialization of the plugin called early during Bro's @@ -568,7 +589,7 @@ protected: * * @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. @@ -594,7 +615,9 @@ protected: * highest to lowest. If two plugins specify the same priority, order * 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 @@ -602,7 +625,9 @@ protected: * * @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, @@ -855,7 +880,10 @@ protected: * * 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 @@ -870,7 +898,9 @@ protected: * implementation for the hook, this will be the default result. If * 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: @@ -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; +} diff --git a/src/plugin/TaggedComponent.h b/src/plugin/TaggedComponent.h index 27ca497171..1fcb8fccc0 100644 --- a/src/plugin/TaggedComponent.h +++ b/src/plugin/TaggedComponent.h @@ -2,7 +2,7 @@ #include -namespace plugin { +namespace zeek::plugin { /** * A class which has a tag of a given type associated with it. @@ -71,3 +71,9 @@ T TaggedComponent::Tag() const template typename T::type_t TaggedComponent::type_counter(0); } // namespace plugin + +namespace plugin { + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; +} diff --git a/src/scan.l b/src/scan.l index 961841daa2..0e4e769d56 100644 --- a/src/scan.l +++ b/src/scan.l @@ -364,7 +364,7 @@ when return TOK_WHEN; @load-sigs{WS}{FILE} { const char* file = skip_whitespace(yytext + 10); 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 ) { case -1: @@ -395,7 +395,7 @@ when return TOK_WHEN; @load-plugin{WS}{ID} { 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 ) { case -1: @@ -615,7 +615,7 @@ static bool already_scanned(const std::string& path) static int load_files(const char* 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 ) return 0; // A plugin took care of it, just skip. diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 36e970a086..1dd339fdf2 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -91,7 +91,7 @@ ValManager* val_mgr = nullptr; logging::Manager* log_mgr = nullptr; threading::Manager* thread_mgr = nullptr; input::Manager* input_mgr = nullptr; -plugin::Manager* plugin_mgr = nullptr; +zeek::plugin::Manager* plugin_mgr = nullptr; analyzer::Manager* analyzer_mgr = nullptr; file_analysis::Manager* file_mgr = nullptr; zeekygen::Manager* zeekygen_mgr = nullptr; @@ -160,7 +160,7 @@ static std::vector to_cargs(const std::vector& args) 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() ) { @@ -175,7 +175,7 @@ bool show_plugins(int level) 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() && requested_plugins.find((*i)->Name()) == requested_plugins.end() ) @@ -191,13 +191,13 @@ bool show_plugins(int level) 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() ) { 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 path = (*i).second; @@ -467,7 +467,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, val_mgr = new ValManager(); reporter = new Reporter(options.abort_on_scripting_errors); thread_mgr = new threading::Manager(); - plugin_mgr = new plugin::Manager(); + plugin_mgr = new zeek::plugin::Manager(); #ifdef DEBUG if ( options.debug_log_streams ) diff --git a/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index 34e6f3519a..71f4c7dfa8 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -21,7 +21,7 @@ using namespace std; 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(); @@ -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()); } -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(); - plugin::Plugin::component_list::const_iterator it; + zeek::plugin::Plugin::component_list components = p->Components(); fprintf(f, "Components\n"); fprintf(f, "++++++++++\n\n"); - for ( it = components.begin(); it != components.end(); ++it ) + for ( const auto& component : components ) { - switch ( (*it)->Type() ) { - case plugin::component::ANALYZER: + switch ( component->Type() ) { + case zeek::plugin::component::ANALYZER: { const analyzer::Component* c = - dynamic_cast(*it); + dynamic_cast(component); if ( c ) write_analyzer_component(f, c); @@ -78,10 +77,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) } break; - case plugin::component::FILE_ANALYZER: + case zeek::plugin::component::FILE_ANALYZER: { const file_analysis::Component* c = - dynamic_cast(*it); + dynamic_cast(component); if ( c ) write_analyzer_component(f, c); @@ -90,10 +89,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) } break; - case plugin::component::READER: + case zeek::plugin::component::READER: reporter->InternalError("docs for READER component unimplemented"); - case plugin::component::WRITER: + case zeek::plugin::component::WRITER: reporter->InternalError("docs for WRITER component unimplemented"); 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, - plugin::BifItem::Type t, const string& heading) +static void write_plugin_bif_items(FILE* f, const zeek::plugin::Plugin* p, + zeek::plugin::BifItem::Type t, const string& heading) { - plugin::Plugin::bif_item_list bifitems = p->BifItems(); - plugin::Plugin::bif_item_list::iterator it = bifitems.begin(); + zeek::plugin::Plugin::bif_item_list bifitems = p->BifItems(); + zeek::plugin::Plugin::bif_item_list::iterator it = bifitems.begin(); while ( it != bifitems.end() ) { @@ -150,11 +149,11 @@ static void WriteAnalyzerTagDefn(FILE* f, const string& module) 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) { - plugin::Plugin::component_list components = p->Components(); - plugin::Plugin::component_list::const_iterator it; + zeek::plugin::Plugin::component_list components = p->Components(); + zeek::plugin::Plugin::component_list::const_iterator it; if ( components.empty() ) return match_empty; @@ -266,22 +265,22 @@ void ProtoAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const WriteAnalyzerTagDefn(f, "Analyzer"); - plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); - plugin::Manager::plugin_list::const_iterator it; + zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); + zeek::plugin::Manager::plugin_list::const_iterator 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; write_plugin_section_heading(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"); - write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals"); - write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types"); - write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events"); - write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions"); } } @@ -292,22 +291,22 @@ void FileAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const WriteAnalyzerTagDefn(f, "Files"); - plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); - plugin::Manager::plugin_list::const_iterator it; + zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); + zeek::plugin::Manager::plugin_list::const_iterator 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; write_plugin_section_heading(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"); - write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals"); - write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types"); - write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events"); - write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions"); } }