Remove Plugin::HookCallFunction and fix tests related to it

This commit is contained in:
Tim Wojtulewicz 2021-01-25 16:36:59 -07:00
parent 725e759560
commit 5f09793ce1
8 changed files with 6 additions and 180 deletions

View file

@ -376,27 +376,7 @@ std::pair<bool, ValPtr>
Plugin::HookFunctionCall(const Func* func, zeek::detail::Frame* parent,
Args* args)
{
ValPList vlargs(args->size());
for ( auto& v : *args )
vlargs.push_back(v.release());
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
auto [handled, result] = HookCallFunction(func, parent, &vlargs);
#pragma GCC diagnostic pop
for ( auto i = 0u; i < args->size(); ++i )
(*args)[i] = {AdoptRef{}, vlargs[i]};
return {handled, {AdoptRef{}, result}};
}
std::pair<bool, Val*> Plugin::HookCallFunction(
const Func* func, zeek::detail::Frame *parent, ValPList* args)
{
std::pair<bool, Val*> result(false, NULL);
return result;
return {false, nullptr};
}
bool Plugin::HookQueueEvent(Event* event)

View file

@ -677,9 +677,6 @@ protected:
virtual std::pair<bool, ValPtr>
HookFunctionCall(const Func* func, zeek::detail::Frame* parent, Args* args);
[[deprecated("Remove in v4.1. Use HookFunctionCall()")]]
virtual std::pair<bool, Val*> HookCallFunction(const Func* func, zeek::detail::Frame *parent, ValPList* args);
/**
* Hook into raising events. Whenever the script interpreter is about
* to queue an event for later execution, it first gives all plugins

View file

@ -56,7 +56,8 @@ int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std
return -1;
}
std::pair<bool, zeek::Val*> Plugin::HookCallFunction(const zeek::Func* func, zeek::detail::Frame* frame, zeek::ValPList* args)
std::pair<bool, zeek::ValPtr> Plugin::HookFunctionCall(const zeek::Func* func, zeek::detail::Frame* frame,
zeek::Args* args)
{
zeek::ODesc d;
d.SetShort();
@ -65,7 +66,7 @@ std::pair<bool, zeek::Val*> Plugin::HookCallFunction(const zeek::Func* func, zee
fprintf(stderr, "%.6f %-15s %s\n", zeek::run_state::network_time, "| HookCallFunction",
d.Description());
return std::pair<bool, zeek::Val*>(false, NULL);
return {false, nullptr};
}
bool Plugin::HookQueueEvent(zeek::Event* event)

View file

@ -9,7 +9,8 @@ class Plugin : public zeek::plugin::Plugin
{
protected:
int HookLoadFile(const LoadType type, const std::string& file, const std::string& resolved) override;
std::pair<bool, zeek::Val*> HookCallFunction(const zeek::Func* func, zeek::detail::Frame* frame, zeek::ValPList* args) override;
std::pair<bool, zeek::ValPtr> HookFunctionCall(const zeek::Func* func, zeek::detail::Frame* parent,
zeek::Args* args) override;
bool HookQueueEvent(zeek::Event* event) override;
void HookDrainEvents() override;
void HookUpdateNetworkTime(double network_time) override;

View file

@ -1,107 +0,0 @@
#include "Plugin.h"
#include <Val.h>
#include <Func.h>
#include <Event.h>
#include <Conn.h>
#include <Desc.h>
#include <threading/Formatter.h>
namespace btest::plugin::Demo_Hooks { Plugin plugin; }
using namespace btest::plugin::Demo_Hooks;
zeek::plugin::Configuration Plugin::Configure()
{
EnableHook(zeek::plugin::HOOK_CALL_FUNCTION);
EnableHook(zeek::plugin::META_HOOK_PRE);
EnableHook(zeek::plugin::META_HOOK_POST);
zeek::plugin::Configuration config;
config.name = "Demo::Hooks";
config.description = "Exercises all plugin hooks";
config.version.major = 1;
config.version.minor = 0;
config.version.patch = 0;
return config;
}
static void describe_hook_args(const zeek::plugin::HookArgumentList& args, zeek::ODesc* d)
{
bool first = true;
for ( zeek::plugin::HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ )
{
if ( ! first )
d->Add(", ");
i->Describe(d);
first = false;
}
}
std::pair<bool, zeek::Val*> Plugin::HookCallFunction(const zeek::Func* func, zeek::detail::Frame* frame,
zeek::ValPList* args)
{
zeek::ODesc d;
d.SetShort();
zeek::plugin::HookArgument(func).Describe(&d);
zeek::plugin::HookArgument(args).Describe(&d);
fprintf(stderr, "%.6f %-15s %s\n", zeek::run_state::network_time, "| HookCallFunction",
d.Description());
if ( zeek::util::streq(func->Name(), "foo") )
{
auto& vl = *args;
Unref(vl[0]);
vl[0] = zeek::val_mgr->Count(13).release();
}
return {};
}
/* std::pair<bool, IntrusivePtr<Val>> Plugin::HookFunctionCall(const Func* func, */
/* Frame* frame, */
/* zeek::Args* args) */
/* { */
/* zeek::ODesc d; */
/* d.SetShort(); */
/* HookArgument(func).Describe(&d); */
/* HookArgument(args).Describe(&d); */
/* fprintf(stderr, "%.6f %-15s %s\n", zeek::run_state::network_time, "| HookFunctionCall", */
/* d.Description()); */
/* if ( streq(func->Name(), "foo") ) */
/* { */
/* auto& vl = *args; */
/* vl[0] = val_mgr->Count(42); */
/* } */
/* return {}; */
/* } */
void Plugin::MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args)
{
zeek::ODesc d;
d.SetShort();
describe_hook_args(args, &d);
fprintf(stderr, "%.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)
{
zeek::ODesc d1;
d1.SetShort();
describe_hook_args(args, &d1);
zeek::ODesc d2;
d2.SetShort();
result.Describe(&d2);
fprintf(stderr, "%.6f %-15s %s(%s) -> %s\n", zeek::run_state::network_time, " MetaHookPost",
hook_name(hook), d1.Description(),
d2.Description());
}

View file

@ -1,29 +0,0 @@
#pragma once
#include <plugin/Plugin.h>
namespace btest::plugin::Demo_Hooks {
class Plugin : public zeek::plugin::Plugin
{
protected:
std::pair<bool, zeek::Val*> HookCallFunction(const zeek::Func* func, zeek::detail::Frame* frame, zeek::ValPList* args) override;
/* std::pair<bool, IntrusivePtr<Val>> HookFunctionCall(const Func* func, */
/* Frame* frame, */
/* zeek::Args* args) 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;
}

View file

@ -1,17 +0,0 @@
# @TEST-EXEC: ${DIST}/auxil/zeek-aux/plugin-support/init-plugin -u . Demo Hooks
# @TEST-EXEC: cp -r %DIR/legacy-func-hook-plugin/* .
# @TEST-EXEC: ./configure --zeek-dist=${DIST} && make
# @TEST-EXEC: ZEEK_PLUGIN_ACTIVATE="Demo::Hooks" ZEEK_PLUGIN_PATH=`pwd` zeek -b %INPUT 2>&1 | grep foo >output
# @TEST-EXEC: btest-diff output
@unload base/misc/version
function foo(a: count, b: count, c: count, s: string)
{
print "foo", a, b, c, s;
}
event zeek_init()
{
foo(1, 2, 3, "yo");
}