Cleanup/improve PList usage and Event API

Majority of PLists are now created as automatic/stack objects,
rather than on heap and initialized either with the known-capacity
reserved upfront or directly from an initializer_list (so there's no
wasted slack in the memory that gets allocated for lists containing
a fixed/known number of elements).

Added versions of the ConnectionEvent/QueueEvent methods that take
a val_list by value.

Added a move ctor/assign-operator to Plists to allow passing them
around without having to copy the underlying array of pointers.
This commit is contained in:
Jon Siwek 2019-04-11 19:02:13 -07:00
parent 78dcbcc71a
commit 8bc65f09ec
92 changed files with 1585 additions and 1679 deletions

View file

@ -216,36 +216,30 @@ void Reporter::Syslog(const char* fmt, ...)
void Reporter::WeirdHelper(EventHandlerPtr event, Val* conn_val, file_analysis::File* f, const char* addl, const char* fmt_name, ...)
{
val_list* vl = new val_list(1);
val_list vl(2);
if ( conn_val )
vl->append(conn_val);
vl.append(conn_val);
else if ( f )
vl->append(f->GetVal()->Ref());
vl.append(f->GetVal()->Ref());
if ( addl )
vl->append(new StringVal(addl));
vl.append(new StringVal(addl));
va_list ap;
va_start(ap, fmt_name);
DoLog("weird", event, 0, 0, vl, false, false, 0, fmt_name, ap);
DoLog("weird", event, 0, 0, &vl, false, false, 0, fmt_name, ap);
va_end(ap);
delete vl;
}
void Reporter::WeirdFlowHelper(const IPAddr& orig, const IPAddr& resp, const char* fmt_name, ...)
{
val_list* vl = new val_list(2);
vl->append(new AddrVal(orig));
vl->append(new AddrVal(resp));
val_list vl{new AddrVal(orig), new AddrVal(resp)};
va_list ap;
va_start(ap, fmt_name);
DoLog("weird", flow_weird, 0, 0, vl, false, false, 0, fmt_name, ap);
DoLog("weird", flow_weird, 0, 0, &vl, false, false, 0, fmt_name, ap);
va_end(ap);
delete vl;
}
void Reporter::UpdateWeirdStats(const char* name)
@ -489,29 +483,32 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out,
if ( raise_event && event && via_events && ! in_error_handler )
{
val_list* vl = new val_list;
auto vl_size = 1 + (bool)time + (bool)location + (bool)conn +
(addl ? addl->length() : 0);
val_list vl(vl_size);
if ( time )
vl->append(new Val((bro_start_network_time != 0.0) ? network_time : 0, TYPE_TIME));
vl.append(new Val((bro_start_network_time != 0.0) ? network_time : 0, TYPE_TIME));
vl->append(new StringVal(buffer));
vl.append(new StringVal(buffer));
if ( location )
vl->append(new StringVal(loc_str.c_str()));
vl.append(new StringVal(loc_str.c_str()));
if ( conn )
vl->append(conn->BuildConnVal());
vl.append(conn->BuildConnVal());
if ( addl )
{
loop_over_list(*addl, i)
vl->append((*addl)[i]);
vl.append((*addl)[i]);
}
if ( conn )
conn->ConnectionEvent(event, 0, vl);
conn->ConnectionEvent(event, 0, std::move(vl));
else
mgr.QueueEvent(event, vl);
mgr.QueueEvent(event, std::move(vl));
}
else
{