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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue