mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Add a method to register an event handler to a std::function via C++
This commit is contained in:
parent
aac723cfe5
commit
39890fda5e
9 changed files with 65 additions and 2 deletions
|
@ -1,19 +1,34 @@
|
|||
|
||||
#include "Foo.h"
|
||||
|
||||
#include "zeek/EventRegistry.h"
|
||||
#include "zeek/analyzer/protocol/tcp/TCP_Reassembler.h"
|
||||
|
||||
#include "events.bif.h"
|
||||
#include "foo_pac.h"
|
||||
|
||||
using namespace btest::plugin::Demo_Foo;
|
||||
using namespace std::placeholders;
|
||||
|
||||
Foo::Foo(zeek::Connection* conn) : zeek::analyzer::tcp::TCP_ApplicationAnalyzer("Foo", conn) {
|
||||
interp = new binpac::Foo::Foo_Conn(this);
|
||||
|
||||
auto handler = zeek::event_registry->Lookup("connection_established");
|
||||
if ( handler ) {
|
||||
handler->GetFunc()->AddBody([](const zeek::Args& args) {
|
||||
printf("c++ connection_established lambda handler, received %zu arguments\n", args.size());
|
||||
});
|
||||
|
||||
handler->GetFunc()->AddBody(std::bind(&Foo::ConnectionEstablishedHandler, this, _1));
|
||||
}
|
||||
}
|
||||
|
||||
Foo::~Foo() { delete interp; }
|
||||
|
||||
void Foo::ConnectionEstablishedHandler(const zeek::Args& args) {
|
||||
printf("c++ connection_established member handler, received %zu arguments\n", args.size());
|
||||
}
|
||||
|
||||
void Foo::Done() {
|
||||
zeek::analyzer::tcp::TCP_ApplicationAnalyzer::Done();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue