Deprecate EventMgr::QueueEventFast() and update usages to Enqueue()

This commit is contained in:
Jon Siwek 2020-03-25 15:20:05 -07:00
parent 0db484cc7a
commit 6980f63a91
27 changed files with 187 additions and 198 deletions

View file

@ -622,18 +622,23 @@ void File::FileEvent(EventHandlerPtr h)
if ( ! FileEventAvailable(h) )
return;
FileEvent(h, {val->Ref()});
FileEvent(h, zeek::Args{{NewRef{}, val}});
}
void File::FileEvent(EventHandlerPtr h, val_list* vl)
{
FileEvent(h, std::move(*vl));
FileEvent(h, zeek::val_list_to_args(vl));
delete vl;
}
void File::FileEvent(EventHandlerPtr h, val_list vl)
{
mgr.QueueEventFast(h, std::move(vl));
FileEvent(h, zeek::val_list_to_args(&vl));
}
void File::FileEvent(EventHandlerPtr h, zeek::Args args)
{
mgr.Enqueue(h, std::move(args));
if ( h == file_new || h == file_over_new_connection ||
h == file_sniff ||

View file

@ -10,6 +10,7 @@
#include "AnalyzerSet.h"
#include "BroString.h"
#include "BroList.h" // for val_list
#include "ZeekArgs.h"
#include "WeirdState.h"
using std::string;
@ -175,6 +176,7 @@ public:
* @param h pointer to an event handler.
* @param vl list of argument values to pass to event call.
*/
// TODO: deprecate
void FileEvent(EventHandlerPtr h, val_list* vl);
/**
@ -182,8 +184,16 @@ public:
* @param h pointer to an event handler.
* @param vl list of argument values to pass to event call.
*/
// TODO: deprecate
void FileEvent(EventHandlerPtr h, val_list vl);
/**
* Raises an event related to the file's life-cycle.
* @param h pointer to an event handler.
* @param args list of argument values to pass to event call.
*/
void FileEvent(EventHandlerPtr h, zeek::Args args);
/**
* Sets the MIME type for a file to a specific value.
*

View file

@ -432,13 +432,12 @@ string Manager::GetFileID(const analyzer::Tag& tag, Connection* c, bool is_orig)
analyzer_mgr->GetComponentName(tag).c_str());
EnumVal* tagval = tag.AsEnumVal();
Ref(tagval);
mgr.QueueEventFast(get_file_handle, {
tagval,
c->BuildConnVal(),
val_mgr->GetBool(is_orig),
});
mgr.Enqueue(get_file_handle,
IntrusivePtr{NewRef{}, tagval},
IntrusivePtr{AdoptRef{}, c->BuildConnVal()},
IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)}
);
mgr.Drain(); // need file handle immediately so we don't have to buffer data
return current_file_id;
}

View file

@ -42,11 +42,11 @@ bool DataEvent::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset)
{
if ( ! chunk_event ) return true;
mgr.QueueEventFast(chunk_event, {
GetFile()->GetVal()->Ref(),
new StringVal(new BroString(data, len, 0)),
val_mgr->GetCount(offset),
});
mgr.Enqueue(chunk_event,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
make_intrusive<StringVal>(new BroString(data, len, 0)),
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(offset)}
);
return true;
}
@ -55,10 +55,10 @@ bool DataEvent::DeliverStream(const u_char* data, uint64_t len)
{
if ( ! stream_event ) return true;
mgr.QueueEventFast(stream_event, {
GetFile()->GetVal()->Ref(),
new StringVal(new BroString(data, len, 0)),
});
mgr.Enqueue(stream_event,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
make_intrusive<StringVal>(new BroString(data, len, 0))
);
return true;
}

View file

@ -60,15 +60,15 @@ void Entropy::Finalize()
montepi = scc = ent = mean = chisq = 0.0;
entropy->Get(&ent, &chisq, &mean, &montepi, &scc);
RecordVal* ent_result = new RecordVal(entropy_test_result);
auto ent_result = make_intrusive<RecordVal>(entropy_test_result);
ent_result->Assign(0, make_intrusive<Val>(ent, TYPE_DOUBLE));
ent_result->Assign(1, make_intrusive<Val>(chisq, TYPE_DOUBLE));
ent_result->Assign(2, make_intrusive<Val>(mean, TYPE_DOUBLE));
ent_result->Assign(3, make_intrusive<Val>(montepi, TYPE_DOUBLE));
ent_result->Assign(4, make_intrusive<Val>(scc, TYPE_DOUBLE));
mgr.QueueEventFast(file_entropy, {
GetFile()->GetVal()->Ref(),
ent_result,
});
mgr.Enqueue(file_entropy,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
std::move(ent_result)
);
}

View file

@ -51,9 +51,9 @@ void Hash::Finalize()
if ( ! file_hash )
return;
mgr.QueueEventFast(file_hash, {
GetFile()->GetVal()->Ref(),
new StringVal(kind),
hash->Get().release(),
});
mgr.Enqueue(file_hash,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
make_intrusive<StringVal>(kind),
hash->Get()
);
}

View file

@ -42,7 +42,7 @@ refine flow File += {
%{
if ( pe_dos_header )
{
RecordVal* dh = new RecordVal(BifType::Record::PE::DOSHeader);
auto dh = make_intrusive<RecordVal>(BifType::Record::PE::DOSHeader);
dh->Assign(0, make_intrusive<StringVal>(${h.signature}.length(), (const char*) ${h.signature}.data()));
dh->Assign(1, val_mgr->GetCount(${h.UsedBytesInTheLastPage}));
dh->Assign(2, val_mgr->GetCount(${h.FileSizeInPages}));
@ -61,10 +61,9 @@ refine flow File += {
dh->Assign(15, val_mgr->GetCount(${h.OEMinfo}));
dh->Assign(16, val_mgr->GetCount(${h.AddressOfNewExeHeader}));
mgr.QueueEventFast(pe_dos_header, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
dh
});
mgr.Enqueue(pe_dos_header,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(dh));
}
return true;
%}
@ -72,12 +71,10 @@ refine flow File += {
function proc_dos_code(code: bytestring): bool
%{
if ( pe_dos_code )
{
mgr.QueueEventFast(pe_dos_code, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
new StringVal(code.length(), (const char*) code.data())
});
}
mgr.Enqueue(pe_dos_code,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
make_intrusive<StringVal>(code.length(), (const char*) code.data())
);
return true;
%}
@ -95,7 +92,7 @@ refine flow File += {
%{
if ( pe_file_header )
{
RecordVal* fh = new RecordVal(BifType::Record::PE::FileHeader);
auto fh = make_intrusive<RecordVal>(BifType::Record::PE::FileHeader);
fh->Assign(0, val_mgr->GetCount(${h.Machine}));
fh->Assign(1, make_intrusive<Val>(static_cast<double>(${h.TimeDateStamp}), TYPE_TIME));
fh->Assign(2, val_mgr->GetCount(${h.PointerToSymbolTable}));
@ -103,10 +100,9 @@ refine flow File += {
fh->Assign(4, val_mgr->GetCount(${h.SizeOfOptionalHeader}));
fh->Assign(5, characteristics_to_bro(${h.Characteristics}, 16));
mgr.QueueEventFast(pe_file_header, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
fh
});
mgr.Enqueue(pe_file_header,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(fh));
}
return true;
@ -124,7 +120,7 @@ refine flow File += {
if ( pe_optional_header )
{
RecordVal* oh = new RecordVal(BifType::Record::PE::OptionalHeader);
auto oh = make_intrusive<RecordVal>(BifType::Record::PE::OptionalHeader);
oh->Assign(0, val_mgr->GetCount(${h.magic}));
oh->Assign(1, val_mgr->GetCount(${h.major_linker_version}));
@ -155,10 +151,9 @@ refine flow File += {
oh->Assign(23, process_rvas(${h.rvas}));
mgr.QueueEventFast(pe_optional_header, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
oh
});
mgr.Enqueue(pe_optional_header,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(oh));
}
return true;
%}
@ -167,7 +162,7 @@ refine flow File += {
%{
if ( pe_section_header )
{
RecordVal* section_header = new RecordVal(BifType::Record::PE::SectionHeader);
auto section_header = make_intrusive<RecordVal>(BifType::Record::PE::SectionHeader);
// Strip null characters from the end of the section name.
u_char* first_null = (u_char*) memchr(${h.name}.data(), 0, ${h.name}.length());
@ -188,10 +183,10 @@ refine flow File += {
section_header->Assign(8, val_mgr->GetCount(${h.non_used_num_of_line_nums}));
section_header->Assign(9, characteristics_to_bro(${h.characteristics}, 32));
mgr.QueueEventFast(pe_section_header, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
section_header
});
mgr.Enqueue(pe_section_header,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(section_header)
);
}
return true;
%}

View file

@ -66,7 +66,7 @@ refine flow Flow += {
%{
if ( ::unified2_event )
{
RecordVal* ids_event = new RecordVal(BifType::Record::Unified2::IDSEvent);
auto ids_event = make_intrusive<RecordVal>(BifType::Record::Unified2::IDSEvent);
ids_event->Assign(0, val_mgr->GetCount(${ev.sensor_id}));
ids_event->Assign(1, val_mgr->GetCount(${ev.event_id}));
ids_event->Assign(2, make_intrusive<Val>(ts_to_double(${ev.ts}), TYPE_TIME));
@ -81,11 +81,9 @@ refine flow Flow += {
ids_event->Assign(11, to_port(${ev.dst_p}, ${ev.protocol}));
ids_event->Assign(17, val_mgr->GetCount(${ev.packet_action}));
mgr.QueueEventFast(::unified2_event, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
ids_event,
},
SOURCE_LOCAL);
mgr.Enqueue(::unified2_event,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(ids_event));
}
return true;
%}
@ -94,7 +92,7 @@ refine flow Flow += {
%{
if ( ::unified2_event )
{
RecordVal* ids_event = new RecordVal(BifType::Record::Unified2::IDSEvent);
auto ids_event = make_intrusive<RecordVal>(BifType::Record::Unified2::IDSEvent);
ids_event->Assign(0, val_mgr->GetCount(${ev.sensor_id}));
ids_event->Assign(1, val_mgr->GetCount(${ev.event_id}));
ids_event->Assign(2, make_intrusive<Val>(ts_to_double(${ev.ts}), TYPE_TIME));
@ -113,11 +111,9 @@ refine flow Flow += {
ids_event->Assign(15, val_mgr->GetCount(${ev.mpls_label}));
ids_event->Assign(16, val_mgr->GetCount(${ev.vlan_id}));
mgr.QueueEventFast(::unified2_event, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
ids_event,
},
SOURCE_LOCAL);
mgr.Enqueue(::unified2_event,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(ids_event));
}
return true;
@ -127,7 +123,7 @@ refine flow Flow += {
%{
if ( ::unified2_packet )
{
RecordVal* packet = new RecordVal(BifType::Record::Unified2::Packet);
auto packet = make_intrusive<RecordVal>(BifType::Record::Unified2::Packet);
packet->Assign(0, val_mgr->GetCount(${pkt.sensor_id}));
packet->Assign(1, val_mgr->GetCount(${pkt.event_id}));
packet->Assign(2, val_mgr->GetCount(${pkt.event_second}));
@ -135,11 +131,9 @@ refine flow Flow += {
packet->Assign(4, val_mgr->GetCount(${pkt.link_type}));
packet->Assign(5, bytestring_to_val(${pkt.packet_data}));
mgr.QueueEventFast(::unified2_packet, {
connection()->bro_analyzer()->GetFile()->GetVal()->Ref(),
packet,
},
SOURCE_LOCAL);
mgr.Enqueue(::unified2_packet,
IntrusivePtr{NewRef{}, connection()->bro_analyzer()->GetFile()->GetVal()},
std::move(packet));
}
return true;

View file

@ -420,10 +420,10 @@ void file_analysis::OCSP::ParseRequest(OCSP_REQUEST* req)
#endif
if ( ocsp_request )
mgr.QueueEventFast(ocsp_request, {
GetFile()->GetVal()->Ref(),
val_mgr->GetCount(version),
});
mgr.Enqueue(ocsp_request,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(version)}
);
BIO *bio = BIO_new(BIO_s_mem());
@ -466,10 +466,10 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp)
StringVal* status_val = new StringVal(strlen(status_str), status_str);
if ( ocsp_response_status )
mgr.QueueEventFast(ocsp_response_status, {
GetFile()->GetVal()->Ref(),
status_val->Ref(),
});
mgr.Enqueue(ocsp_response_status,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
IntrusivePtr{NewRef{}, status_val}
);
//if (!resp_bytes)
// {

View file

@ -289,16 +289,16 @@ void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex)
{
if ( x509_ext_basic_constraints )
{
RecordVal* pBasicConstraint = new RecordVal(BifType::Record::X509::BasicConstraints);
auto pBasicConstraint = make_intrusive<RecordVal>(BifType::Record::X509::BasicConstraints);
pBasicConstraint->Assign(0, val_mgr->GetBool(constr->ca ? 1 : 0));
if ( constr->pathlen )
pBasicConstraint->Assign(1, val_mgr->GetCount((int32_t) ASN1_INTEGER_get(constr->pathlen)));
mgr.QueueEventFast(x509_ext_basic_constraints, {
GetFile()->GetVal()->Ref(),
pBasicConstraint,
});
mgr.Enqueue(x509_ext_basic_constraints,
IntrusivePtr{NewRef{}, GetFile()->GetVal()},
std::move(pBasicConstraint)
);
}
BASIC_CONSTRAINTS_free(constr);

View file

@ -38,15 +38,15 @@ refine connection MockConnection += {
if ( ! x509_ocsp_ext_signed_certificate_timestamp )
return true;
mgr.QueueEventFast(x509_ocsp_ext_signed_certificate_timestamp, {
bro_analyzer()->GetFile()->GetVal()->Ref(),
val_mgr->GetCount(version),
new StringVal(logid.length(), reinterpret_cast<const char*>(logid.begin())),
val_mgr->GetCount(timestamp),
val_mgr->GetCount(digitally_signed_algorithms->HashAlgorithm()),
val_mgr->GetCount(digitally_signed_algorithms->SignatureAlgorithm()),
new StringVal(digitally_signed_signature.length(), reinterpret_cast<const char*>(digitally_signed_signature.begin()))
});
mgr.Enqueue(x509_ocsp_ext_signed_certificate_timestamp,
IntrusivePtr{NewRef{}, bro_analyzer()->GetFile()->GetVal()},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(version)},
make_intrusive<StringVal>(logid.length(), reinterpret_cast<const char*>(logid.begin())),
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(timestamp)},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(digitally_signed_algorithms->HashAlgorithm())},
IntrusivePtr{AdoptRef{}, val_mgr->GetCount(digitally_signed_algorithms->SignatureAlgorithm())},
make_intrusive<StringVal>(digitally_signed_signature.length(), reinterpret_cast<const char*>(digitally_signed_signature.begin()))
);
return true;
%}