mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
A test with a plugin exercising all hooks.
This commit is contained in:
parent
ee75958951
commit
fdd386a898
5 changed files with 2546 additions and 1 deletions
2421
testing/btest/Baseline/core.plugins.hooks/output
Normal file
2421
testing/btest/Baseline/core.plugins.hooks/output
Normal file
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
||||||
Demo::Foo
|
|
0
testing/btest/core/plugins/hooks-plugin/.btest-ignore
Normal file
0
testing/btest/core/plugins/hooks-plugin/.btest-ignore
Normal file
119
testing/btest/core/plugins/hooks-plugin/src/Plugin.cc
Normal file
119
testing/btest/core/plugins/hooks-plugin/src/Plugin.cc
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
|
||||||
|
#include <plugin/Plugin.h>
|
||||||
|
|
||||||
|
#include <Func.h>
|
||||||
|
#include <Event.h>
|
||||||
|
|
||||||
|
namespace plugin {
|
||||||
|
namespace Demo_Hooks {
|
||||||
|
|
||||||
|
class Plugin : public plugin::Plugin
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
plugin::Configuration Configure()
|
||||||
|
{
|
||||||
|
EnableHook(HOOK_LOAD_FILE);
|
||||||
|
EnableHook(HOOK_CALL_FUNCTION);
|
||||||
|
EnableHook(HOOK_QUEUE_EVENT);
|
||||||
|
EnableHook(HOOK_DRAIN_EVENTS);
|
||||||
|
EnableHook(HOOK_UPDATE_NETWORK_TIME);
|
||||||
|
EnableHook(META_HOOK_PRE);
|
||||||
|
EnableHook(META_HOOK_POST);
|
||||||
|
|
||||||
|
plugin::Configuration config;
|
||||||
|
config.name = "Demo::Hooks";
|
||||||
|
config.description = "Exercises all plugin hooks";
|
||||||
|
config.version.major = 1;
|
||||||
|
config.version.minor = 0;
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int HookLoadFile(const std::string& file);
|
||||||
|
virtual Val* HookCallFunction(const Func* func, val_list* args);
|
||||||
|
virtual bool HookQueueEvent(Event* event);
|
||||||
|
virtual void HookDrainEvents();
|
||||||
|
virtual void HookUpdateNetworkTime(double network_time);
|
||||||
|
virtual void MetaHookPre(HookType hook, const HookArgumentList& args);
|
||||||
|
virtual void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result);
|
||||||
|
|
||||||
|
} plugin;
|
||||||
|
|
||||||
|
static void describe_hook_args(const HookArgumentList& args, ODesc* d)
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
|
||||||
|
for ( HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ )
|
||||||
|
{
|
||||||
|
if ( ! first )
|
||||||
|
d->Add(", ");
|
||||||
|
|
||||||
|
i->Describe(d);
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Plugin::HookLoadFile(const std::string& file)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookLoadFile",
|
||||||
|
file.c_str());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Val* Plugin::HookCallFunction(const Func* func, val_list* args)
|
||||||
|
{
|
||||||
|
ODesc d;
|
||||||
|
d.SetShort();
|
||||||
|
HookArgument(func).Describe(&d);
|
||||||
|
HookArgument(args).Describe(&d);
|
||||||
|
fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookCallFunction",
|
||||||
|
d.Description());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Plugin::HookQueueEvent(Event* event)
|
||||||
|
{
|
||||||
|
ODesc d;
|
||||||
|
d.SetShort();
|
||||||
|
HookArgument(event).Describe(&d);
|
||||||
|
fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookQueueEvent",
|
||||||
|
d.Description());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::HookDrainEvents()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%.6f %-15s\n", network_time, "| HookDrainEvents");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::HookUpdateNetworkTime(double network_time)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%.6f %-15s %.6f\n", ::network_time, "| HookUpdateNetworkTime",
|
||||||
|
network_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args)
|
||||||
|
{
|
||||||
|
ODesc d;
|
||||||
|
d.SetShort();
|
||||||
|
describe_hook_args(args, &d);
|
||||||
|
fprintf(stderr, "%.6f %-15s %s(%s)\n", network_time, " MetaHookPre",
|
||||||
|
hook_name(hook), d.Description());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result)
|
||||||
|
{
|
||||||
|
ODesc d1;
|
||||||
|
d1.SetShort();
|
||||||
|
describe_hook_args(args, &d1);
|
||||||
|
|
||||||
|
ODesc d2;
|
||||||
|
d2.SetShort();
|
||||||
|
result.Describe(&d2);
|
||||||
|
|
||||||
|
fprintf(stderr, "%.6f %-15s %s(%s) -> %s\n", network_time, " MetaHookPost",
|
||||||
|
hook_name(hook), d1.Description(),
|
||||||
|
d2.Description());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
6
testing/btest/core/plugins/hooks.bro
Normal file
6
testing/btest/core/plugins/hooks.bro
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin Demo Hooks
|
||||||
|
# @TEST-EXEC: cp -r %DIR/hooks-plugin/* .
|
||||||
|
# @TEST-EXEC: make BRO=${DIST}
|
||||||
|
# @TEST-EXEC: BRO_PLUGIN_PATH=`pwd` bro -r $TRACES/http/get.trace %INPUT >output 2>&1
|
||||||
|
# @TEST-EXEC: btest-diff output
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue