mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
Initial import of svn+ssh:://svn.icir.org/bro/trunk/bro as of r7088
This commit is contained in:
commit
61757ac78b
1383 changed files with 380824 additions and 0 deletions
166
src/Event.cc
Normal file
166
src/Event.cc
Normal file
|
@ -0,0 +1,166 @@
|
|||
// $Id: Event.cc 6219 2008-10-01 05:39:07Z vern $
|
||||
//
|
||||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "Event.h"
|
||||
#include "Func.h"
|
||||
#include "NetVar.h"
|
||||
#include "Trigger.h"
|
||||
|
||||
EventMgr mgr;
|
||||
|
||||
int num_events_queued = 0;
|
||||
int num_events_dispatched = 0;
|
||||
|
||||
Event::Event(EventHandlerPtr arg_handler, val_list* arg_args,
|
||||
SourceID arg_src, AnalyzerID arg_aid, TimerMgr* arg_mgr,
|
||||
BroObj* arg_obj)
|
||||
{
|
||||
handler = arg_handler;
|
||||
args = arg_args;
|
||||
src = arg_src;
|
||||
mgr = arg_mgr ? arg_mgr : timer_mgr; // default is global
|
||||
aid = arg_aid;
|
||||
obj = arg_obj;
|
||||
|
||||
if ( obj )
|
||||
Ref(obj);
|
||||
|
||||
next_event = 0;
|
||||
}
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
// We don't Unref() the individual arguments by using delete_vals()
|
||||
// here, because Func::Call already did that.
|
||||
delete args;
|
||||
}
|
||||
|
||||
void Event::Describe(ODesc* d) const
|
||||
{
|
||||
if ( d->IsReadable() )
|
||||
d->AddSP("event");
|
||||
|
||||
int s = d->IsShort();
|
||||
d->SetShort();
|
||||
// handler->Describe(d);
|
||||
d->SetShort(s);
|
||||
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("(");
|
||||
describe_vals(args, d);
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("(");
|
||||
}
|
||||
|
||||
EventMgr::EventMgr()
|
||||
{
|
||||
head = tail = 0;
|
||||
current_src = SOURCE_LOCAL;
|
||||
current_mgr = timer_mgr;
|
||||
current_aid = 0;
|
||||
src_val = 0;
|
||||
draining = 0;
|
||||
}
|
||||
|
||||
EventMgr::~EventMgr()
|
||||
{
|
||||
while ( head )
|
||||
{
|
||||
Event* n = head->NextEvent();
|
||||
Unref(head);
|
||||
head = n;
|
||||
}
|
||||
|
||||
Unref(src_val);
|
||||
}
|
||||
|
||||
void EventMgr::QueueEvent(Event* event)
|
||||
{
|
||||
if ( ! head )
|
||||
head = tail = event;
|
||||
else
|
||||
{
|
||||
tail->SetNext(event);
|
||||
tail = event;
|
||||
}
|
||||
|
||||
++num_events_queued;
|
||||
}
|
||||
|
||||
void EventMgr::Dispatch()
|
||||
{
|
||||
if ( ! head )
|
||||
internal_error("EventMgr underflow");
|
||||
|
||||
Event* current = head;
|
||||
|
||||
head = head->NextEvent();
|
||||
if ( ! head )
|
||||
tail = head;
|
||||
|
||||
current_src = current->Source();
|
||||
current_mgr = current->Mgr();
|
||||
current_aid = current->Analyzer();
|
||||
current->Dispatch();
|
||||
Unref(current);
|
||||
|
||||
++num_events_dispatched;
|
||||
}
|
||||
|
||||
void EventMgr::Drain()
|
||||
{
|
||||
SegmentProfiler(segment_logger, "draining-events");
|
||||
|
||||
draining = true;
|
||||
while ( head )
|
||||
Dispatch();
|
||||
|
||||
// Note: we might eventually need a general way to specify things to
|
||||
// do after draining events.
|
||||
extern void flush_rewriter_packet();
|
||||
flush_rewriter_packet();
|
||||
|
||||
draining = false;
|
||||
|
||||
// We evaluate Triggers here. While this is somewhat unrelated to event
|
||||
// processing, we ensure that it's done at a regular basis by checking
|
||||
// them here.
|
||||
Trigger::EvaluatePending();
|
||||
}
|
||||
|
||||
void EventMgr::Describe(ODesc* d) const
|
||||
{
|
||||
int n = 0;
|
||||
Event* e;
|
||||
for ( e = head; e; e = e->NextEvent() )
|
||||
++n;
|
||||
|
||||
d->AddCount(n);
|
||||
|
||||
for ( e = head; e; e = e->NextEvent() )
|
||||
{
|
||||
e->Describe(d);
|
||||
d->NL();
|
||||
}
|
||||
}
|
||||
|
||||
RecordVal* EventMgr::GetLocalPeerVal()
|
||||
{
|
||||
if ( ! src_val )
|
||||
{
|
||||
src_val = new RecordVal(peer);
|
||||
src_val->Assign(0, new Val(0, TYPE_COUNT));
|
||||
src_val->Assign(1, new AddrVal("127.0.0.1"));
|
||||
src_val->Assign(2, new PortVal(0));
|
||||
src_val->Assign(3, new Val(true, TYPE_BOOL));
|
||||
|
||||
Ref(peer_description);
|
||||
src_val->Assign(4, peer_description);
|
||||
src_val->Assign(5, 0); // class (optional).
|
||||
}
|
||||
|
||||
return src_val;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue