mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
Merge branch 'improve-container-record-fields-bif' of https://github.com/henridf/zeek
- Minor whitespace adjustment in merge * 'improve-container-record-fields-bif' of https://github.com/henridf/zeek: Recursively handle into container types in record_fields() tabify Apply suggestions from code review Print full container types in record_fields()
This commit is contained in:
commit
ca48a1865d
5 changed files with 56 additions and 7 deletions
4
CHANGES
4
CHANGES
|
@ -1,4 +1,8 @@
|
|||
|
||||
3.1.0-dev.263 | 2019-11-13 13:43:16 -0800
|
||||
|
||||
* Improve record_fields() BIF to recursively give full container type names (Henri DF)
|
||||
|
||||
3.1.0-dev.257 | 2019-11-11 13:40:11 -0800
|
||||
|
||||
* Update embedded CAF to 0.17.3 (Jon Siwek, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
3.1.0-dev.257
|
||||
3.1.0-dev.263
|
||||
|
|
40
src/Type.cc
40
src/Type.cc
|
@ -824,6 +824,38 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const
|
|||
d->PopType(this);
|
||||
}
|
||||
|
||||
static string container_type_name(const BroType* ft)
|
||||
{
|
||||
string s;
|
||||
if ( ft->Tag() == TYPE_RECORD )
|
||||
s = "record " + ft->GetName();
|
||||
else if ( ft->Tag() == TYPE_VECTOR )
|
||||
s = "vector of " + container_type_name(ft->YieldType());
|
||||
else if ( ft->Tag() == TYPE_TABLE )
|
||||
{
|
||||
if ( ft->IsSet() )
|
||||
s = "set[";
|
||||
else
|
||||
s = "table[";
|
||||
const type_list* tl = ((const IndexType*) ft)->IndexTypes();
|
||||
loop_over_list(*tl, i)
|
||||
{
|
||||
if ( i > 0 )
|
||||
s += ",";
|
||||
s += container_type_name((*tl)[i]);
|
||||
}
|
||||
s += "]";
|
||||
if ( ft->YieldType() )
|
||||
{
|
||||
s += " of ";
|
||||
s += container_type_name(ft->YieldType());
|
||||
}
|
||||
}
|
||||
else
|
||||
s = type_name(ft->Tag());
|
||||
return s;
|
||||
}
|
||||
|
||||
TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
|
||||
{
|
||||
auto rval = new TableVal(internal_type("record_field_table")->AsTableType());
|
||||
|
@ -844,15 +876,11 @@ TableVal* RecordType::GetRecordFieldsVal(const RecordVal* rv) const
|
|||
|
||||
RecordVal* nr = new RecordVal(internal_type("record_field")->AsRecordType());
|
||||
|
||||
if ( ft->Tag() == TYPE_RECORD )
|
||||
nr->Assign(0, new StringVal("record " + ft->GetName()));
|
||||
else
|
||||
nr->Assign(0, new StringVal(type_name(ft->Tag())));
|
||||
|
||||
string s = container_type_name(ft);
|
||||
nr->Assign(0, new StringVal(s));
|
||||
nr->Assign(1, val_mgr->GetBool(logged));
|
||||
nr->Assign(2, fv);
|
||||
nr->Assign(3, FieldDefault(i));
|
||||
|
||||
Val* field_name = new StringVal(FieldName(i));
|
||||
rval->Assign(field_name, nr);
|
||||
Unref(field_name);
|
||||
|
|
|
@ -48,3 +48,10 @@ F
|
|||
[a] = [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>]
|
||||
}
|
||||
{
|
||||
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||
[c] = [type_name=set[double,record r], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||
[e] = [type_name=vector of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||
[d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>]
|
||||
}
|
||||
|
|
|
@ -24,6 +24,14 @@ type r: record {
|
|||
|
||||
type mystring: string;
|
||||
|
||||
type cr: record {
|
||||
a: set[double];
|
||||
b: set[double, string];
|
||||
c: set[double, r];
|
||||
d: table[double, string] of table[string] of vector of string;
|
||||
e: vector of vector of string;
|
||||
};
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
local x: r = [$a=42, $d="Bar", $e=tt];
|
||||
|
@ -47,4 +55,6 @@ event zeek_init()
|
|||
print record_fields("myrec");
|
||||
print record_fields("tt");
|
||||
print record_fields("r");
|
||||
|
||||
print record_fields("cr");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue