mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 15:18:20 +00:00
Port remaining file analysis API to use IntrusivePtr
This commit is contained in:
parent
57a6069cd1
commit
b1042e2824
8 changed files with 117 additions and 75 deletions
|
@ -40,60 +40,54 @@ AnalyzerSet::~AnalyzerSet()
|
|||
delete analyzer_hash;
|
||||
}
|
||||
|
||||
Analyzer* AnalyzerSet::Find(const file_analysis::Tag& tag, RecordVal* args)
|
||||
Analyzer* AnalyzerSet::Find(const file_analysis::Tag& tag,
|
||||
IntrusivePtr<RecordVal> args)
|
||||
{
|
||||
HashKey* key = GetKey(tag, args);
|
||||
Analyzer* rval = analyzer_map.Lookup(key);
|
||||
delete key;
|
||||
auto key = GetKey(tag, std::move(args));
|
||||
Analyzer* rval = analyzer_map.Lookup(key.get());
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool AnalyzerSet::Add(const file_analysis::Tag& tag, RecordVal* args)
|
||||
bool AnalyzerSet::Add(const file_analysis::Tag& tag, IntrusivePtr<RecordVal> args)
|
||||
{
|
||||
HashKey* key = GetKey(tag, args);
|
||||
auto key = GetKey(tag, args);
|
||||
|
||||
if ( analyzer_map.Lookup(key) )
|
||||
if ( analyzer_map.Lookup(key.get()) )
|
||||
{
|
||||
DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Instantiate analyzer %s skipped: already exists",
|
||||
file->GetID().c_str(),
|
||||
file_mgr->GetComponentName(tag).c_str());
|
||||
|
||||
delete key;
|
||||
return true;
|
||||
}
|
||||
|
||||
file_analysis::Analyzer* a = InstantiateAnalyzer(tag, args);
|
||||
file_analysis::Analyzer* a = InstantiateAnalyzer(tag, std::move(args));
|
||||
|
||||
if ( ! a )
|
||||
{
|
||||
delete key;
|
||||
return false;
|
||||
}
|
||||
|
||||
Insert(a, key);
|
||||
Insert(a, std::move(key));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Analyzer* AnalyzerSet::QueueAdd(const file_analysis::Tag& tag, RecordVal* args)
|
||||
Analyzer* AnalyzerSet::QueueAdd(const file_analysis::Tag& tag,
|
||||
IntrusivePtr<RecordVal> args)
|
||||
{
|
||||
HashKey* key = GetKey(tag, args);
|
||||
file_analysis::Analyzer* a = InstantiateAnalyzer(tag, args);
|
||||
auto key = GetKey(tag, args);
|
||||
file_analysis::Analyzer* a = InstantiateAnalyzer(tag, std::move(args));
|
||||
|
||||
if ( ! a )
|
||||
{
|
||||
delete key;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mod_queue.push(new AddMod(a, key));
|
||||
mod_queue.push(new AddMod(a, std::move(key)));
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set)
|
||||
{
|
||||
if ( set->analyzer_map.Lookup(key) )
|
||||
if ( set->analyzer_map.Lookup(key.get()) )
|
||||
{
|
||||
DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Add analyzer %s skipped: already exists",
|
||||
a->GetFile()->GetID().c_str(),
|
||||
|
@ -103,7 +97,7 @@ bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set)
|
|||
return true;
|
||||
}
|
||||
|
||||
set->Insert(a, key);
|
||||
set->Insert(a, std::move(key));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -111,20 +105,18 @@ bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set)
|
|||
void AnalyzerSet::AddMod::Abort()
|
||||
{
|
||||
delete a;
|
||||
delete key;
|
||||
}
|
||||
|
||||
bool AnalyzerSet::Remove(const file_analysis::Tag& tag, RecordVal* args)
|
||||
bool AnalyzerSet::Remove(const file_analysis::Tag& tag,
|
||||
IntrusivePtr<RecordVal> args)
|
||||
{
|
||||
return Remove(tag, GetKey(tag, args));
|
||||
return Remove(tag, GetKey(tag, std::move(args)));
|
||||
}
|
||||
|
||||
bool AnalyzerSet::Remove(const file_analysis::Tag& tag, HashKey* key)
|
||||
bool AnalyzerSet::Remove(const file_analysis::Tag& tag,
|
||||
std::unique_ptr<HashKey> key)
|
||||
{
|
||||
file_analysis::Analyzer* a =
|
||||
(file_analysis::Analyzer*) analyzer_map.Remove(key);
|
||||
|
||||
delete key;
|
||||
auto a = (file_analysis::Analyzer*) analyzer_map.Remove(key.get());
|
||||
|
||||
if ( ! a )
|
||||
{
|
||||
|
@ -147,37 +139,38 @@ bool AnalyzerSet::Remove(const file_analysis::Tag& tag, HashKey* key)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AnalyzerSet::QueueRemove(const file_analysis::Tag& tag, RecordVal* args)
|
||||
bool AnalyzerSet::QueueRemove(const file_analysis::Tag& tag,
|
||||
IntrusivePtr<RecordVal> args)
|
||||
{
|
||||
HashKey* key = GetKey(tag, args);
|
||||
|
||||
mod_queue.push(new RemoveMod(tag, key));
|
||||
|
||||
return analyzer_map.Lookup(key);
|
||||
auto key = GetKey(tag, std::move(args));
|
||||
auto rval = analyzer_map.Lookup(key.get());
|
||||
mod_queue.push(new RemoveMod(tag, std::move(key)));
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set)
|
||||
{
|
||||
return set->Remove(tag, key);
|
||||
return set->Remove(tag, std::move(key));
|
||||
}
|
||||
|
||||
HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const
|
||||
std::unique_ptr<HashKey> AnalyzerSet::GetKey(const file_analysis::Tag& t,
|
||||
IntrusivePtr<RecordVal> args) const
|
||||
{
|
||||
auto lv = make_intrusive<ListVal>(TYPE_ANY);
|
||||
lv->Append(t.AsVal());
|
||||
lv->Append({NewRef{}, args});
|
||||
lv->Append(std::move(args));
|
||||
auto key = analyzer_hash->MakeHashKey(*lv, true);
|
||||
|
||||
if ( ! key )
|
||||
reporter->InternalError("AnalyzerArgs type mismatch");
|
||||
|
||||
return key.release();
|
||||
return key;
|
||||
}
|
||||
|
||||
file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag,
|
||||
RecordVal* args) const
|
||||
IntrusivePtr<RecordVal> args) const
|
||||
{
|
||||
auto a = file_mgr->InstantiateAnalyzer(tag, {NewRef{}, args}, file);
|
||||
auto a = file_mgr->InstantiateAnalyzer(tag, std::move(args), file);
|
||||
|
||||
if ( ! a )
|
||||
{
|
||||
|
@ -190,12 +183,12 @@ file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag,
|
|||
return a;
|
||||
}
|
||||
|
||||
void AnalyzerSet::Insert(file_analysis::Analyzer* a, HashKey* key)
|
||||
void AnalyzerSet::Insert(file_analysis::Analyzer* a,
|
||||
std::unique_ptr<HashKey> key)
|
||||
{
|
||||
DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Add analyzer %s",
|
||||
file->GetID().c_str(), file_mgr->GetComponentName(a->Tag()).c_str());
|
||||
analyzer_map.Insert(key, a);
|
||||
delete key;
|
||||
analyzer_map.Insert(key.get(), a);
|
||||
|
||||
a->Init();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue