mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 21:48:21 +00:00
plugin/Manager: Fix MetaHookPre and MetaHookPost using HOOK_CALL_FUNCTION
This commit is contained in:
parent
3b478ddc0a
commit
6d97d5526a
10 changed files with 166 additions and 2 deletions
0
testing/btest/plugins/meta-hook-plugin/.btest-ignore
Normal file
0
testing/btest/plugins/meta-hook-plugin/.btest-ignore
Normal file
83
testing/btest/plugins/meta-hook-plugin/src/Plugin.cc
Normal file
83
testing/btest/plugins/meta-hook-plugin/src/Plugin.cc
Normal file
|
@ -0,0 +1,83 @@
|
|||
|
||||
#include "Plugin.h"
|
||||
|
||||
#include <zeek/Desc.h>
|
||||
#include <zeek/Event.h>
|
||||
#include <zeek/Func.h>
|
||||
#include <zeek/threading/Formatter.h>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace btest::plugin::Demo_Meta_Hooks {
|
||||
Plugin plugin;
|
||||
}
|
||||
|
||||
using namespace btest::plugin::Demo_Meta_Hooks;
|
||||
|
||||
zeek::plugin::Configuration Plugin::Configure() {
|
||||
zeek::plugin::Configuration config;
|
||||
config.name = "Demo::Meta_Hooks";
|
||||
config.description = "Test if the meta hooks are working";
|
||||
config.version.major = 1;
|
||||
config.version.minor = 0;
|
||||
config.version.patch = 0;
|
||||
|
||||
// This plugin enables HookQueueEvent() and optionally the pre and post
|
||||
// meta hooks controlled by environment variables for easier testing.
|
||||
|
||||
EnableHook(zeek::plugin::HOOK_QUEUE_EVENT);
|
||||
|
||||
if ( getenv("TEST_META_HOOK_PRE") )
|
||||
EnableHook(zeek::plugin::META_HOOK_PRE);
|
||||
|
||||
if ( getenv("TEST_META_HOOK_POST") )
|
||||
EnableHook(zeek::plugin::META_HOOK_POST);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
static void describe_hook_args(const zeek::plugin::HookArgumentList& args, zeek::ODesc* d) {
|
||||
bool first = true;
|
||||
|
||||
for ( const auto& arg : args ) {
|
||||
if ( ! first )
|
||||
d->Add(", ");
|
||||
|
||||
arg.Describe(d);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Plugin::HookQueueEvent(zeek::Event* e) {
|
||||
fprintf(stdout, "%.6f %-15s %s()\n", zeek::run_state::network_time, " HookQueueEvent", e->Handler()->Name());
|
||||
return false;
|
||||
}
|
||||
|
||||
void Plugin::MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) {
|
||||
// The spicy integration enables HOOK_LOAD_FILE and this plugin receives
|
||||
// meta hooks also for that :-/
|
||||
if ( hook != zeek::plugin::HOOK_QUEUE_EVENT )
|
||||
return;
|
||||
|
||||
zeek::ODesc d;
|
||||
d.SetShort();
|
||||
describe_hook_args(args, &d);
|
||||
fprintf(stdout, "%.6f %-15s %s(%s)\n", zeek::run_state::network_time, " MetaHookPre", hook_name(hook),
|
||||
d.Description());
|
||||
}
|
||||
|
||||
void Plugin::MetaHookPost(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args,
|
||||
zeek::plugin::HookArgument result) {
|
||||
// The spicy integration enables HOOK_LOAD_FILE and this plugin receives
|
||||
// meta hooks also for that :-/
|
||||
if ( hook != zeek::plugin::HOOK_QUEUE_EVENT )
|
||||
return;
|
||||
|
||||
zeek::ODesc d1;
|
||||
zeek::ODesc d2;
|
||||
describe_hook_args(args, &d1);
|
||||
result.Describe(&d2);
|
||||
|
||||
fprintf(stdout, "%.6f %-15s %s(%s) -> %s\n", zeek::run_state::network_time, " MetaHookPost", hook_name(hook),
|
||||
d1.Description(), d2.Description());
|
||||
}
|
21
testing/btest/plugins/meta-hook-plugin/src/Plugin.h
Normal file
21
testing/btest/plugins/meta-hook-plugin/src/Plugin.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <zeek/plugin/Plugin.h>
|
||||
|
||||
namespace btest::plugin::Demo_Meta_Hooks {
|
||||
|
||||
class Plugin : public zeek::plugin::Plugin {
|
||||
protected:
|
||||
bool HookQueueEvent(zeek::Event* e) override;
|
||||
void MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) override;
|
||||
void MetaHookPost(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args,
|
||||
zeek::plugin::HookArgument result) override;
|
||||
|
||||
// Overridden from plugin::Plugin.
|
||||
zeek::plugin::Configuration Configure() override;
|
||||
};
|
||||
|
||||
extern Plugin plugin;
|
||||
|
||||
} // namespace btest::plugin::Demo_Meta_Hooks
|
Loading…
Add table
Add a link
Reference in a new issue