mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Merge remote-tracking branch 'origin/topic/timw/598-multikey-set-json'
Adjustments: - Changed a push_back(...) into emplace_back(std:move(...)) - Removed superfluous table Lookup() since we already have the value while iterating * origin/topic/timw/598-multikey-set-json: GH-598: handle multi-key sets correctly when outputting json
This commit is contained in:
commit
3d4fef012a
3 changed files with 16 additions and 20 deletions
33
src/Val.cc
33
src/Val.cc
|
@ -537,34 +537,26 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
||||||
j = ZeekJson::object();
|
j = ZeekJson::object();
|
||||||
|
|
||||||
HashKey* k;
|
HashKey* k;
|
||||||
|
TableEntryVal* entry;
|
||||||
auto c = table->InitForIteration();
|
auto c = table->InitForIteration();
|
||||||
while ( table->NextEntry(k, c) )
|
while ( (entry = table->NextEntry(k, c)) )
|
||||||
{
|
{
|
||||||
auto lv = tval->RecoverIndex(k);
|
auto lv = tval->RecoverIndex(k);
|
||||||
delete k;
|
delete k;
|
||||||
|
|
||||||
if ( tval->Type()->IsSet() )
|
Val* entry_key;
|
||||||
{
|
|
||||||
auto* value = lv->Index(0)->Ref();
|
|
||||||
j.push_back(BuildJSON(value, only_loggable, re));
|
|
||||||
Unref(value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ZeekJson key_json;
|
|
||||||
Val* entry_value;
|
|
||||||
if ( lv->Length() == 1 )
|
if ( lv->Length() == 1 )
|
||||||
{
|
entry_key = lv->Index(0)->Ref();
|
||||||
Val* entry_key = lv->Index(0)->Ref();
|
else
|
||||||
entry_value = tval->Lookup(entry_key, true);
|
entry_key = lv->Ref();
|
||||||
key_json = BuildJSON(entry_key, only_loggable, re);
|
|
||||||
Unref(entry_key);
|
ZeekJson key_json = BuildJSON(entry_key, only_loggable, re);
|
||||||
}
|
|
||||||
|
if ( tval->Type()->IsSet() )
|
||||||
|
j.emplace_back(std::move(key_json));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entry_value = tval->Lookup(lv, true);
|
Val* entry_value = entry->Value();
|
||||||
key_json = BuildJSON(lv, only_loggable, re);
|
|
||||||
}
|
|
||||||
|
|
||||||
string key_string;
|
string key_string;
|
||||||
if ( key_json.is_string() )
|
if ( key_json.is_string() )
|
||||||
|
@ -575,6 +567,7 @@ static ZeekJson BuildJSON(Val* val, bool only_loggable=false, RE_Matcher* re=new
|
||||||
j[key_string] = BuildJSON(entry_value, only_loggable, re);
|
j[key_string] = BuildJSON(entry_value, only_loggable, re);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Unref(entry_key);
|
||||||
Unref(lv);
|
Unref(lv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ true
|
||||||
["1.2.3.4"]
|
["1.2.3.4"]
|
||||||
[{"s":"test"}]
|
[{"s":"test"}]
|
||||||
[{"s":"test"}]
|
[{"s":"test"}]
|
||||||
|
[["three",3],["one",1],["two",2]]
|
||||||
{}
|
{}
|
||||||
{"2":"10.2.2.2","1":"10.1.1.1"}
|
{"2":"10.2.2.2","1":"10.1.1.1"}
|
||||||
{"10.1.1.1":{"a":1},"10.2.2.2":{"b":2}}
|
{"10.1.1.1":{"a":1},"10.2.2.2":{"b":2}}
|
||||||
|
|
|
@ -105,11 +105,13 @@ event zeek_init()
|
||||||
local st3: set[addr] = set(1.2.3.4);
|
local st3: set[addr] = set(1.2.3.4);
|
||||||
local st4: set[myrec1] = set(myrec1($s="test"));
|
local st4: set[myrec1] = set(myrec1($s="test"));
|
||||||
local st5: set[myrec1] = set(myrec1($s="test", $c=2));
|
local st5: set[myrec1] = set(myrec1($s="test", $c=2));
|
||||||
|
local st6: set[string, count] = { ["one", 1], ["two", 2], ["three", 3] };
|
||||||
print to_json(st1);
|
print to_json(st1);
|
||||||
print to_json(st2);
|
print to_json(st2);
|
||||||
print to_json(st3);
|
print to_json(st3);
|
||||||
print to_json(st4);
|
print to_json(st4);
|
||||||
print to_json(st5, T);
|
print to_json(st5, T);
|
||||||
|
print to_json(st6);
|
||||||
|
|
||||||
# Tables
|
# Tables
|
||||||
local ta1: table[count] of addr = table();
|
local ta1: table[count] of addr = table();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue