diff --git a/src/analyzer/analyzer.bif b/src/analyzer/analyzer.bif index 0bd666fac6..1252a352a2 100644 --- a/src/analyzer/analyzer.bif +++ b/src/analyzer/analyzer.bif @@ -50,7 +50,7 @@ function __name%(atype: AllAnalyzers::Tag%) : string if ( ! component ) return zeek::make_intrusive(""); - return zeek::make_intrusive(component->CanonicalName()); + return component->CanonicalNameVal(); %} function __tag%(name: string%) : AllAnalyzers::Tag diff --git a/src/file_analysis/file_analysis.bif b/src/file_analysis/file_analysis.bif index bb738cd27b..8f427a8fec 100644 --- a/src/file_analysis/file_analysis.bif +++ b/src/file_analysis/file_analysis.bif @@ -103,8 +103,7 @@ function Files::__stop%(file_id: string%): bool ## :zeek:see:`Files::analyzer_name`. function Files::__analyzer_name%(tag: Files::Tag%) : string %{ - const auto& n = zeek::file_mgr->GetComponentName(zeek::IntrusivePtr{zeek::NewRef{}, tag->AsEnumVal()}); - return zeek::make_intrusive(n); + return zeek::file_mgr->GetComponentNameVal(zeek::IntrusivePtr{zeek::NewRef{}, tag->AsEnumVal()}); %} ## :zeek:see:`Files::file_exists`. diff --git a/src/plugin/Component.cc b/src/plugin/Component.cc index b2fafbad0c..eaa1f21118 100644 --- a/src/plugin/Component.cc +++ b/src/plugin/Component.cc @@ -16,6 +16,7 @@ Component::Component(component::Type arg_type, const std::string& arg_name, tag_subtype(tag_subtype) { canon_name = util::canonify_name(name); + canon_name_val = make_intrusive(canon_name); } void Component::Describe(ODesc* d) const diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 4472bd91c2..57ce88d699 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -8,6 +8,7 @@ #include "zeek/Tag.h" #include "zeek/Type.h" +#include "zeek/Val.h" namespace zeek { @@ -98,6 +99,7 @@ public: * ID. */ const std::string& CanonicalName() const { return canon_name; } + StringValPtr CanonicalNameVal() const { return canon_name_val; } /** * Returns a textual representation of the component. This goes into @@ -135,6 +137,7 @@ private: component::Type type; std::string name; std::string canon_name; + StringValPtr canon_name_val; /** The automatically assigned component tag */ zeek::Tag tag; diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 3021982040..1d3dfcb411 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -74,6 +74,22 @@ public: */ const std::string& GetComponentName(EnumValPtr val) const; + /** + * Get a component name from its tag. + * + * @param tag A component's tag. + * @return The canonical component name as a StringValPtr. + */ + StringValPtr GetComponentNameVal(zeek::Tag tag) const; + + /** + * Get a component name from it's enum value. + * + * @param val A component's enum value. + * @return The canonical component name as a StringValPtr. + */ + StringValPtr GetComponentNameVal(EnumValPtr val) const; + /** * Get a component tag from its name. * @@ -216,6 +232,35 @@ template const std::string& ComponentManager::GetComponentName(Enum return error; } +template StringValPtr ComponentManager::GetComponentNameVal(zeek::Tag tag) const + { + static auto error = make_intrusive(""); + + if ( ! tag ) + return error; + + if ( C* c = Lookup(tag) ) + return c->CanonicalNameVal(); + + reporter->InternalWarning("requested name of unknown component tag %s", tag.AsString().c_str()); + return error; + } + +template StringValPtr ComponentManager::GetComponentNameVal(EnumValPtr val) const + { + static auto error = make_intrusive(""); + + if ( ! val ) + return error; + + if ( C* c = Lookup(val.get()) ) + return c->CanonicalNameVal(); + + reporter->InternalWarning("requested name of unknown component tag %s", + val->AsString()->CheckString()); + return error; + } + template zeek::Tag ComponentManager::GetComponentTag(const std::string& name) const { C* c = Lookup(name);