mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
use differentiated record field accessors
This commit is contained in:
parent
e363bab55f
commit
931cec4e06
10 changed files with 21 additions and 15 deletions
|
@ -631,7 +631,7 @@ void Connection::CheckFlowLabel(bool is_orig, uint32_t flow_label)
|
||||||
{
|
{
|
||||||
if ( conn_val )
|
if ( conn_val )
|
||||||
{
|
{
|
||||||
RecordVal* endp = conn_val->GetField(is_orig ? 1 : 2)->AsRecordVal();
|
RecordVal* endp = conn_val->GetFieldAs<RecordVal>(is_orig ? 1 : 2);
|
||||||
endp->Assign(4, val_mgr->Count(flow_label));
|
endp->Assign(4, val_mgr->Count(flow_label));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ Substring::Vec* Substring::VecFromPolicy(VectorVal* vec)
|
||||||
const String* str = v->GetFieldAs<StringVal>(0);
|
const String* str = v->GetFieldAs<StringVal>(0);
|
||||||
auto* substr = new Substring(*str);
|
auto* substr = new Substring(*str);
|
||||||
|
|
||||||
const VectorVal* aligns = v->GetField(1)->AsVectorVal();
|
const VectorVal* aligns = v->GetFieldAs<VectorVal>(1);
|
||||||
for ( unsigned int j = 1; j <= aligns->Size(); ++j )
|
for ( unsigned int j = 1; j <= aligns->Size(); ++j )
|
||||||
{
|
{
|
||||||
const RecordVal* align = aligns->AsVectorVal()->RecordValAt(j);
|
const RecordVal* align = aligns->AsVectorVal()->RecordValAt(j);
|
||||||
|
|
|
@ -1310,6 +1310,9 @@ protected:
|
||||||
static RecordTypeValMap parse_time_records;
|
static RecordTypeValMap parse_time_records;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Just for template inferencing.
|
||||||
|
RecordVal* Get() { return this; }
|
||||||
|
|
||||||
// Keep this handy for quick access during low-level operations.
|
// Keep this handy for quick access during low-level operations.
|
||||||
RecordTypePtr rt;
|
RecordTypePtr rt;
|
||||||
|
|
||||||
|
@ -1479,6 +1482,10 @@ protected:
|
||||||
ValPtr DoClone(CloneState* state) override;
|
ValPtr DoClone(CloneState* state) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Just for template inferencing.
|
||||||
|
friend class RecordVal;
|
||||||
|
VectorVal* Get() { return this; }
|
||||||
|
|
||||||
// Check the type of the given element against our current
|
// Check the type of the given element against our current
|
||||||
// yield type and adjust as necessary. Returns whether the
|
// yield type and adjust as necessary. Returns whether the
|
||||||
// element type-checked.
|
// element type-checked.
|
||||||
|
|
|
@ -171,8 +171,8 @@ void ConnSize_Analyzer::SetDurationThreshold(double duration)
|
||||||
void ConnSize_Analyzer::UpdateConnVal(RecordVal *conn_val)
|
void ConnSize_Analyzer::UpdateConnVal(RecordVal *conn_val)
|
||||||
{
|
{
|
||||||
// RecordType *connection_type is decleared in NetVar.h
|
// RecordType *connection_type is decleared in NetVar.h
|
||||||
RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal();
|
RecordVal* orig_endp = conn_val->GetFieldAs<RecordVal>("orig");
|
||||||
RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal();
|
RecordVal* resp_endp = conn_val->GetFieldAs<RecordVal>("resp");
|
||||||
|
|
||||||
// endpoint is the RecordType from NetVar.h
|
// endpoint is the RecordType from NetVar.h
|
||||||
int pktidx = id::endpoint->FieldOffset("num_pkts");
|
int pktidx = id::endpoint->FieldOffset("num_pkts");
|
||||||
|
|
|
@ -126,8 +126,8 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
RecordVal* rv = c->RequestVal()->AsRecordVal();
|
RecordVal* rv = c->RequestVal()->AsRecordVal();
|
||||||
const auto& is_tcp = rv->GetField(2);
|
auto is_tcp = rv->GetFieldAs<BoolVal>(2);
|
||||||
reply = val_mgr->Port(CheckPort(port), is_tcp->IsOne() ?
|
reply = val_mgr->Port(CheckPort(port), is_tcp ?
|
||||||
TRANSPORT_TCP : TRANSPORT_UDP);
|
TRANSPORT_TCP : TRANSPORT_UDP);
|
||||||
event = pm_request_getport;
|
event = pm_request_getport;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1099,7 +1099,7 @@ void TCP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig,
|
||||||
{
|
{
|
||||||
SynWeirds(flags, endpoint, len);
|
SynWeirds(flags, endpoint, len);
|
||||||
RecordVal* SYN_vals = build_syn_packet_val(is_orig, ip, tp);
|
RecordVal* SYN_vals = build_syn_packet_val(is_orig, ip, tp);
|
||||||
init_window(endpoint, peer, flags, SYN_vals->GetField(5)->CoerceToInt(),
|
init_window(endpoint, peer, flags, SYN_vals->GetFieldAs<IntVal>(5),
|
||||||
base_seq, ack_seq);
|
base_seq, ack_seq);
|
||||||
|
|
||||||
if ( connection_SYN_packet )
|
if ( connection_SYN_packet )
|
||||||
|
@ -1282,8 +1282,8 @@ void TCP_Analyzer::FlipRoles()
|
||||||
|
|
||||||
void TCP_Analyzer::UpdateConnVal(RecordVal *conn_val)
|
void TCP_Analyzer::UpdateConnVal(RecordVal *conn_val)
|
||||||
{
|
{
|
||||||
RecordVal* orig_endp_val = conn_val->GetField("orig")->AsRecordVal();
|
auto orig_endp_val = conn_val->GetFieldAs<RecordVal>("orig");
|
||||||
RecordVal* resp_endp_val = conn_val->GetField("resp")->AsRecordVal();
|
auto resp_endp_val = conn_val->GetFieldAs<RecordVal>("resp");
|
||||||
|
|
||||||
orig_endp_val->Assign(0, val_mgr->Count(orig->Size()));
|
orig_endp_val->Assign(0, val_mgr->Count(orig->Size()));
|
||||||
orig_endp_val->Assign(1, val_mgr->Count(int(orig->state)));
|
orig_endp_val->Assign(1, val_mgr->Count(int(orig->state)));
|
||||||
|
|
|
@ -220,8 +220,8 @@ void UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig,
|
||||||
|
|
||||||
void UDP_Analyzer::UpdateConnVal(RecordVal* conn_val)
|
void UDP_Analyzer::UpdateConnVal(RecordVal* conn_val)
|
||||||
{
|
{
|
||||||
RecordVal* orig_endp = conn_val->GetField("orig")->AsRecordVal();
|
auto orig_endp = conn_val->GetFieldAs<RecordVal>("orig");
|
||||||
RecordVal* resp_endp = conn_val->GetField("resp")->AsRecordVal();
|
auto resp_endp = conn_val->GetFieldAs<RecordVal>("resp");
|
||||||
|
|
||||||
UpdateEndpointVal(orig_endp, true);
|
UpdateEndpointVal(orig_endp, true);
|
||||||
UpdateEndpointVal(resp_endp, false);
|
UpdateEndpointVal(resp_endp, false);
|
||||||
|
|
|
@ -437,7 +437,7 @@ bool Manager::PublishEvent(string topic, RecordVal* args)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto event_name = args->GetFieldAs<StringVal>(0)->CheckString();
|
auto event_name = args->GetFieldAs<StringVal>(0)->CheckString();
|
||||||
auto vv = args->GetField(1)->AsVectorVal();
|
auto vv = args->GetFieldAs<VectorVal>(1);
|
||||||
broker::vector xs;
|
broker::vector xs;
|
||||||
xs.reserve(vv->Size());
|
xs.reserve(vv->Size());
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ broker::backend_options to_backend_options(broker::backend backend,
|
||||||
switch ( backend ) {
|
switch ( backend ) {
|
||||||
case broker::backend::sqlite:
|
case broker::backend::sqlite:
|
||||||
{
|
{
|
||||||
auto path = options->GetField(0)->AsRecordVal()
|
auto path = options->GetFieldAs<RecordVal>(0)
|
||||||
->GetFieldAs<StringVal>(0)->CheckString();
|
->GetFieldAs<StringVal>(0)->CheckString();
|
||||||
return {{"path", path}};
|
return {{"path", path}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3435,8 +3435,7 @@ function lookup_connection%(cid: conn_id%): connection
|
||||||
%%{
|
%%{
|
||||||
const char* conn_id_string(zeek::Val* c)
|
const char* conn_id_string(zeek::Val* c)
|
||||||
{
|
{
|
||||||
auto id = c->As<zeek::RecordVal*>()->GetField(0);
|
auto id_r = c->As<zeek::RecordVal*>()->GetFieldAs<zeek::RecordVal>(0);
|
||||||
auto id_r = id->As<zeek::RecordVal*>();
|
|
||||||
|
|
||||||
const zeek::IPAddr& orig_h = id_r->GetFieldAs<zeek::AddrVal>(0);
|
const zeek::IPAddr& orig_h = id_r->GetFieldAs<zeek::AddrVal>(0);
|
||||||
uint32_t orig_p = id_r->GetFieldAs<zeek::PortVal>(1)->Port();
|
uint32_t orig_p = id_r->GetFieldAs<zeek::PortVal>(1)->Port();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue