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();
|
||||
|
||||
HashKey* k;
|
||||
TableEntryVal* entry;
|
||||
auto c = table->InitForIteration();
|
||||
while ( table->NextEntry(k, c) )
|
||||
while ( (entry = table->NextEntry(k, c)) )
|
||||
{
|
||||
auto lv = tval->RecoverIndex(k);
|
||||
delete k;
|
||||
|
||||
Val* entry_key;
|
||||
if ( lv->Length() == 1 )
|
||||
entry_key = lv->Index(0)->Ref();
|
||||
else
|
||||
entry_key = lv->Ref();
|
||||
|
||||
ZeekJson key_json = BuildJSON(entry_key, only_loggable, re);
|
||||
|
||||
if ( tval->Type()->IsSet() )
|
||||
{
|
||||
auto* value = lv->Index(0)->Ref();
|
||||
j.push_back(BuildJSON(value, only_loggable, re));
|
||||
Unref(value);
|
||||
}
|
||||
j.emplace_back(std::move(key_json));
|
||||
else
|
||||
{
|
||||
ZeekJson key_json;
|
||||
Val* entry_value;
|
||||
if ( lv->Length() == 1 )
|
||||
{
|
||||
Val* entry_key = lv->Index(0)->Ref();
|
||||
entry_value = tval->Lookup(entry_key, true);
|
||||
key_json = BuildJSON(entry_key, only_loggable, re);
|
||||
Unref(entry_key);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry_value = tval->Lookup(lv, true);
|
||||
key_json = BuildJSON(lv, only_loggable, re);
|
||||
}
|
||||
Val* entry_value = entry->Value();
|
||||
|
||||
string key_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);
|
||||
}
|
||||
|
||||
Unref(entry_key);
|
||||
Unref(lv);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ true
|
|||
["1.2.3.4"]
|
||||
[{"s":"test"}]
|
||||
[{"s":"test"}]
|
||||
[["three",3],["one",1],["two",2]]
|
||||
{}
|
||||
{"2":"10.2.2.2","1":"10.1.1.1"}
|
||||
{"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 st4: set[myrec1] = set(myrec1($s="test"));
|
||||
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(st2);
|
||||
print to_json(st3);
|
||||
print to_json(st4);
|
||||
print to_json(st5, T);
|
||||
print to_json(st6);
|
||||
|
||||
# Tables
|
||||
local ta1: table[count] of addr = table();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue