diff --git a/src/BroDoc.cc b/src/BroDoc.cc index 93d8a34848..0a1006bd07 100644 --- a/src/BroDoc.cc +++ b/src/BroDoc.cc @@ -473,7 +473,7 @@ static void WritePluginSectionHeading(FILE* f, const plugin::Plugin* p) static void WriteAnalyzerComponent(FILE* f, const analyzer::Component* c) { EnumType* atag = analyzer_mgr->GetTagEnumType(); - string tag = fmt("ANALYZER_%s", c->CanonicalName()); + string tag = fmt("ANALYZER_%s", c->CanonicalName().c_str()); if ( atag->Lookup("Analyzer", tag.c_str()) < 0 ) reporter->InternalError("missing analyzer tag for %s", tag.c_str()); @@ -484,7 +484,7 @@ static void WriteAnalyzerComponent(FILE* f, const analyzer::Component* c) static void WriteAnalyzerComponent(FILE* f, const file_analysis::Component* c) { EnumType* atag = file_mgr->GetTagEnumType(); - string tag = fmt("ANALYZER_%s", c->CanonicalName()); + string tag = fmt("ANALYZER_%s", c->CanonicalName().c_str()); if ( atag->Lookup("Files", tag.c_str()) < 0 ) reporter->InternalError("missing analyzer tag for %s", tag.c_str()); diff --git a/src/RuleAction.cc b/src/RuleAction.cc index ec57c96bd2..8c6948ad10 100644 --- a/src/RuleAction.cc +++ b/src/RuleAction.cc @@ -60,11 +60,11 @@ RuleActionAnalyzer::RuleActionAnalyzer(const char* arg_analyzer) void RuleActionAnalyzer::PrintDebug() { if ( ! child_analyzer ) - fprintf(stderr, "|%s|\n", analyzer_mgr->GetComponentName(analyzer)); + fprintf(stderr, "|%s|\n", analyzer_mgr->GetComponentName(analyzer).c_str()); else fprintf(stderr, "|%s:%s|\n", - analyzer_mgr->GetComponentName(analyzer), - analyzer_mgr->GetComponentName(child_analyzer)); + analyzer_mgr->GetComponentName(analyzer).c_str(), + analyzer_mgr->GetComponentName(child_analyzer).c_str()); } diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index 2927e3ad97..1e4f0e20f4 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -75,7 +75,7 @@ analyzer::ID Analyzer::id_counter = 0; const char* Analyzer::GetAnalyzerName() const { assert(tag); - return analyzer_mgr->GetComponentName(tag); + return analyzer_mgr->GetComponentName(tag).c_str(); } void Analyzer::SetAnalyzerTag(const Tag& arg_tag) @@ -87,7 +87,7 @@ void Analyzer::SetAnalyzerTag(const Tag& arg_tag) bool Analyzer::IsAnalyzer(const char* name) { assert(tag); - return strcmp(analyzer_mgr->GetComponentName(tag), name) == 0; + return strcmp(analyzer_mgr->GetComponentName(tag).c_str(), name) == 0; } // Used in debugging output. diff --git a/src/analyzer/Component.cc b/src/analyzer/Component.cc index 255e03435c..91528b29d8 100644 --- a/src/analyzer/Component.cc +++ b/src/analyzer/Component.cc @@ -8,12 +8,11 @@ using namespace analyzer; -Component::Component(const char* arg_name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial) - : plugin::Component(plugin::component::ANALYZER), +Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial) + : plugin::Component(plugin::component::ANALYZER, name), plugin::TaggedComponent(arg_subtype) { - name = copy_string(arg_name); - canon_name = canonify_name(arg_name); + canon_name = canonify_name(name); factory = arg_factory; enabled = arg_enabled; partial = arg_partial; @@ -21,31 +20,12 @@ Component::Component(const char* arg_name, factory_callback arg_factory, Tag::su analyzer_mgr->RegisterComponent(this, "ANALYZER_"); } -Component::Component(const Component& other) - : plugin::Component(Type()), - plugin::TaggedComponent(other) - { - name = copy_string(other.name); - canon_name = copy_string(other.canon_name); - factory = other.factory; - enabled = other.enabled; - partial = other.partial; - - // TODO: Do we need the RegisterComponent() call here? - } - Component::~Component() { - delete [] name; - delete [] canon_name; } -void Component::Describe(ODesc* d) const +void Component::DoDescribe(ODesc* d) const { - plugin::Component::Describe(d); - d->Add(name); - d->Add(" ("); - if ( factory ) { d->Add("ANALYZER_"); @@ -54,20 +34,4 @@ void Component::Describe(ODesc* d) const } d->Add(enabled ? "enabled" : "disabled"); - d->Add(")"); - } - -Component& Component::operator=(const Component& other) - { - plugin::TaggedComponent::operator=(other); - - if ( &other != this ) - { - name = copy_string(other.name); - factory = other.factory; - enabled = other.enabled; - partial = other.partial; - } - - return *this; } diff --git a/src/analyzer/Component.h b/src/analyzer/Component.h index 9bc8b357d7..d8a62bb38c 100644 --- a/src/analyzer/Component.h +++ b/src/analyzer/Component.h @@ -1,7 +1,7 @@ // See the file "COPYING" in the main distribution directory for copyright. -#ifndef ANALYZER_PLUGIN_COMPONENT_H -#define ANALYZER_PLUGIN_COMPONENT_H +#ifndef ANALYZER_COMPONENT_H +#define ANALYZER_COMPONENT_H #include "Tag.h" #include "plugin/Component.h" @@ -56,33 +56,20 @@ public: * connections has generally not seen much testing yet as virtually * no existing analyzer supports it. */ - Component(const char* name, factory_callback factory, Tag::subtype_t subtype = 0, bool enabled = true, bool partial = false); - - /** - * Copy constructor. - */ - Component(const Component& other); + Component(const std::string& name, factory_callback factory, Tag::subtype_t subtype = 0, bool enabled = true, bool partial = false); /** * Destructor. */ ~Component(); - /** - * Returns the name of the analyzer. This name is unique across all - * analyzers and used to identify it. The returned name is derived - * from what's passed to the constructor but upper-cased and - * canonified to allow being part of a script-level ID. - */ - virtual const char* Name() const { return name; } - /** * Returns a canonocalized version of the analyzer's name. The * returned name is derived from what's passed to the constructor but * upper-cased and transformed to allow being part of a script-level * ID. */ - const char* CanonicalName() const { return canon_name; } + const std::string& CanonicalName() const { return canon_name; } /** * Returns the analyzer's factory function. @@ -110,17 +97,14 @@ public: */ void SetEnabled(bool arg_enabled) { enabled = arg_enabled; } +protected: /** - * Generates a human-readable description of the component's main - * parameters. This goes into the output of \c "bro -NN". - */ - virtual void Describe(ODesc* d) const; - - Component& operator=(const Component& other); + * Overriden from plugin::Component. + */ + virtual void DoDescribe(ODesc* d) const; private: - const char* name; // The analyzer's name. - const char* canon_name; // The analyzer's canonical name. + std::string canon_name; // The analyzer's canonical name. factory_callback factory; // The analyzer's factory callback. bool partial; // True if the analyzer supports partial connections. bool enabled; // True if the analyzer is enabled. diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 748af34dfb..e2cd2a7e05 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -104,7 +104,8 @@ void Manager::DumpDebug() DBG_LOG(DBG_ANALYZER, "Available analyzers after bro_init():"); list all_analyzers = GetComponents(); for ( list::const_iterator i = all_analyzers.begin(); i != all_analyzers.end(); ++i ) - DBG_LOG(DBG_ANALYZER, " %s (%s)", (*i)->Name(), IsEnabled((*i)->Tag()) ? "enabled" : "disabled"); + DBG_LOG(DBG_ANALYZER, " %s (%s)", (*i)->Name().c_str(), + IsEnabled((*i)->Tag()) ? "enabled" : "disabled"); DBG_LOG(DBG_ANALYZER, ""); DBG_LOG(DBG_ANALYZER, "Analyzers by port:"); @@ -143,7 +144,7 @@ bool Manager::EnableAnalyzer(Tag tag) if ( ! p ) return false; - DBG_LOG(DBG_ANALYZER, "Enabling analyzer %s", p->Name()); + DBG_LOG(DBG_ANALYZER, "Enabling analyzer %s", p->Name().c_str()); p->SetEnabled(true); return true; @@ -156,7 +157,7 @@ bool Manager::EnableAnalyzer(EnumVal* val) if ( ! p ) return false; - DBG_LOG(DBG_ANALYZER, "Enabling analyzer %s", p->Name()); + DBG_LOG(DBG_ANALYZER, "Enabling analyzer %s", p->Name().c_str()); p->SetEnabled(true); return true; @@ -169,7 +170,7 @@ bool Manager::DisableAnalyzer(Tag tag) if ( ! p ) return false; - DBG_LOG(DBG_ANALYZER, "Disabling analyzer %s", p->Name()); + DBG_LOG(DBG_ANALYZER, "Disabling analyzer %s", p->Name().c_str()); p->SetEnabled(false); return true; @@ -182,7 +183,7 @@ bool Manager::DisableAnalyzer(EnumVal* val) if ( ! p ) return false; - DBG_LOG(DBG_ANALYZER, "Disabling analyzer %s", p->Name()); + DBG_LOG(DBG_ANALYZER, "Disabling analyzer %s", p->Name().c_str()); p->SetEnabled(false); return true; @@ -254,7 +255,7 @@ bool Manager::RegisterAnalyzerForPort(Tag tag, TransportProto proto, uint32 port return false; #ifdef DEBUG - const char* name = GetComponentName(tag); + const char* name = GetComponentName(tag).c_str(); DBG_LOG(DBG_ANALYZER, "Registering analyzer %s for port %" PRIu32 "/%d", name, port, proto); #endif @@ -270,7 +271,7 @@ bool Manager::UnregisterAnalyzerForPort(Tag tag, TransportProto proto, uint32 po return true; // still a "successful" unregistration #ifdef DEBUG - const char* name = GetComponentName(tag); + const char* name = GetComponentName(tag).c_str(); DBG_LOG(DBG_ANALYZER, "Unregistering analyzer %s for port %" PRIu32 "/%d", name, port, proto); #endif @@ -293,7 +294,8 @@ Analyzer* Manager::InstantiateAnalyzer(Tag tag, Connection* conn) if ( ! c->Factory() ) { - reporter->InternalWarning("analyzer %s cannot be instantiated dynamically", GetComponentName(tag)); + reporter->InternalWarning("analyzer %s cannot be instantiated dynamically", + GetComponentName(tag).c_str()); return 0; } @@ -403,7 +405,7 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) root->AddChildAnalyzer(analyzer, false); DBG_ANALYZER_ARGS(conn, "activated %s analyzer as scheduled", - analyzer_mgr->GetComponentName(*i)); + analyzer_mgr->GetComponentName(*i).c_str()); } } @@ -429,7 +431,7 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn) root->AddChildAnalyzer(analyzer, false); DBG_ANALYZER_ARGS(conn, "activated %s analyzer due to port %d", - analyzer_mgr->GetComponentName(*j), resp_port); + analyzer_mgr->GetComponentName(*j).c_str(), resp_port); } } } @@ -555,7 +557,7 @@ void Manager::ExpireScheduledAnalyzers() conns.erase(i); DBG_LOG(DBG_ANALYZER, "Expiring expected analyzer %s for connection %s", - analyzer_mgr->GetComponentName(a->analyzer), + analyzer_mgr->GetComponentName(a->analyzer).c_str(), fmt_conn_id(a->conn.orig, 0, a->conn.resp, a->conn.resp_p)); delete a; diff --git a/src/file_analysis/Analyzer.cc b/src/file_analysis/Analyzer.cc index 2d45c6579a..c04c02f818 100644 --- a/src/file_analysis/Analyzer.cc +++ b/src/file_analysis/Analyzer.cc @@ -8,7 +8,7 @@ file_analysis::ID file_analysis::Analyzer::id_counter = 0; file_analysis::Analyzer::~Analyzer() { DBG_LOG(DBG_FILE_ANALYSIS, "Destroy file analyzer %s", - file_mgr->GetComponentName(tag)); + file_mgr->GetComponentName(tag).c_str()); Unref(args); } diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index aee5e0d62e..b3f11b6816 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -53,7 +53,7 @@ bool AnalyzerSet::Add(file_analysis::Tag tag, RecordVal* args) if ( analyzer_map.Lookup(key) ) { DBG_LOG(DBG_FILE_ANALYSIS, "Instantiate analyzer %s skipped for file id" - " %s: already exists", file_mgr->GetComponentName(tag), + " %s: already exists", file_mgr->GetComponentName(tag).c_str(), file->GetID().c_str()); delete key; return true; @@ -93,7 +93,7 @@ bool AnalyzerSet::AddMod::Perform(AnalyzerSet* set) if ( set->analyzer_map.Lookup(key) ) { DBG_LOG(DBG_FILE_ANALYSIS, "Add analyzer %s skipped for file id" - " %s: already exists", file_mgr->GetComponentName(a->Tag()), + " %s: already exists", file_mgr->GetComponentName(a->Tag()).c_str(), a->GetFile()->GetID().c_str()); Abort(); @@ -120,12 +120,12 @@ bool AnalyzerSet::Remove(file_analysis::Tag tag, HashKey* key) if ( ! a ) { DBG_LOG(DBG_FILE_ANALYSIS, "Skip remove analyzer %s for file id %s", - file_mgr->GetComponentName(tag), file->GetID().c_str()); + file_mgr->GetComponentName(tag).c_str(), file->GetID().c_str()); return false; } DBG_LOG(DBG_FILE_ANALYSIS, "Remove analyzer %s for file id %s", - file_mgr->GetComponentName(tag), + file_mgr->GetComponentName(tag).c_str(), file->GetID().c_str()); a->Done(); @@ -169,7 +169,7 @@ file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(Tag tag, if ( ! a ) { reporter->Error("Failed file analyzer %s instantiation for file id %s", - file_mgr->GetComponentName(tag), file->GetID().c_str()); + file_mgr->GetComponentName(tag).c_str(), file->GetID().c_str()); return 0; } @@ -179,7 +179,7 @@ file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(Tag tag, void AnalyzerSet::Insert(file_analysis::Analyzer* a, HashKey* key) { DBG_LOG(DBG_FILE_ANALYSIS, "Add analyzer %s for file id %s", - file_mgr->GetComponentName(a->Tag()), file->GetID().c_str()); + file_mgr->GetComponentName(a->Tag()).c_str(), file->GetID().c_str()); analyzer_map.Insert(key, a); delete key; diff --git a/src/file_analysis/Component.cc b/src/file_analysis/Component.cc index 87789eb113..dc30b95986 100644 --- a/src/file_analysis/Component.cc +++ b/src/file_analysis/Component.cc @@ -8,58 +8,25 @@ using namespace file_analysis; -Component::Component(const char* arg_name, factory_callback arg_factory, Tag::subtype_t subtype) - : plugin::Component(plugin::component::FILE_ANALYZER), +Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t subtype) + : plugin::Component(plugin::component::FILE_ANALYZER, name), plugin::TaggedComponent(subtype) { - name = copy_string(arg_name); - canon_name = canonify_name(arg_name); + canon_name = canonify_name(name); factory = arg_factory; file_mgr->RegisterComponent(this, "ANALYZER_"); } -Component::Component(const Component& other) - : plugin::Component(Type()), - plugin::TaggedComponent(other) - { - name = copy_string(other.name); - canon_name = copy_string(other.canon_name); - factory = other.factory; - - // TODO: Do we need the RegisterComponent() call here? - } - Component::~Component() { - delete [] name; - delete [] canon_name; } -void Component::Describe(ODesc* d) const +void Component::DoDescribe(ODesc* d) const { - plugin::Component::Describe(d); - d->Add(name); - d->Add(" ("); - if ( factory ) { d->Add("ANALYZER_"); d->Add(canon_name); } - - d->Add(")"); - } - -Component& Component::operator=(const Component& other) - { - plugin::TaggedComponent::operator=(other); - - if ( &other != this ) - { - name = copy_string(other.name); - factory = other.factory; - } - - return *this; } diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 6e2809349d..8f3b628a32 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -1,7 +1,7 @@ // See the file "COPYING" in the main distribution directory for copyright. -#ifndef FILE_ANALYZER_PLUGIN_COMPONENT_H -#define FILE_ANALYZER_PLUGIN_COMPONENT_H +#ifndef FILE_ANALYZER_COMPONENT_H +#define FILE_ANALYZER_COMPONENT_H #include "Tag.h" #include "plugin/Component.h" @@ -47,50 +47,34 @@ public: * analyzer instances can accordingly access it via analyzer::Tag(). * If not used, leave at zero. */ - Component(const char* name, factory_callback factory, Tag::subtype_t subtype = 0); - - /** - * Copy constructor. - */ - Component(const Component& other); + Component(const std::string& name, factory_callback factory, Tag::subtype_t subtype = 0); /** * Destructor. */ ~Component(); - /** - * Returns the name of the analyzer. This name is unique across all - * analyzers and used to identify it. The returned name is derived - * from what's passed to the constructor but upper-cased and - * canonified to allow being part of a script-level ID. - */ - virtual const char* Name() const { return name; } - /** * Returns a canonocalized version of the analyzer's name. The * returned name is derived from what's passed to the constructor but * upper-cased and transformed to allow being part of a script-level * ID. */ - const char* CanonicalName() const { return canon_name; } + const std::string& CanonicalName() const { return canon_name; } /** * Returns the analyzer's factory function. */ factory_callback Factory() const { return factory; } +protected: /** - * Generates a human-readable description of the component's main - * parameters. This goes into the output of \c "bro -NN". - */ - virtual void Describe(ODesc* d) const; - - Component& operator=(const Component& other); + * Overriden from plugin::Component. + */ + virtual void DoDescribe(ODesc* d) const; private: - const char* name; // The analyzer's name. - const char* canon_name; // The analyzer's canonical name. + std::string canon_name; // The analyzer's canonical name. factory_callback factory; // The analyzer's factory callback. }; diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 980a8bfbce..6c15f47094 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -254,7 +254,7 @@ void File::ScheduleInactivityTimer() const bool File::AddAnalyzer(file_analysis::Tag tag, RecordVal* args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing addition of %s analyzer", - id.c_str(), file_mgr->GetComponentName(tag)); + id.c_str(), file_mgr->GetComponentName(tag).c_str()); return done ? false : analyzers.QueueAdd(tag, args); } @@ -262,7 +262,7 @@ bool File::AddAnalyzer(file_analysis::Tag tag, RecordVal* args) bool File::RemoveAnalyzer(file_analysis::Tag tag, RecordVal* args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing remove of %s analyzer", - id.c_str(), file_mgr->GetComponentName(tag)); + id.c_str(), file_mgr->GetComponentName(tag).c_str()); return done ? false : analyzers.QueueRemove(tag, args); } diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index a635a5dc14..de930e7589 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -351,7 +351,7 @@ void Manager::GetFileHandle(analyzer::Tag tag, Connection* c, bool is_orig) return; DBG_LOG(DBG_FILE_ANALYSIS, "Raise get_file_handle() for protocol analyzer %s", - analyzer_mgr->GetComponentName(tag)); + analyzer_mgr->GetComponentName(tag).c_str()); EnumVal* tagval = tag.AsEnumVal(); Ref(tagval); @@ -398,12 +398,12 @@ Analyzer* Manager::InstantiateAnalyzer(Tag tag, RecordVal* args, File* f) const if ( ! c->Factory() ) { reporter->InternalWarning("file analyzer %s cannot be instantiated " - "dynamically", c->CanonicalName()); + "dynamically", c->CanonicalName().c_str()); return 0; } DBG_LOG(DBG_FILE_ANALYSIS, "Instantiate analyzer %s for file %s", - GetComponentName(tag), f->id.c_str()); + GetComponentName(tag).c_str(), f->id.c_str()); Analyzer* a = c->Factory()(args, f); @@ -445,7 +445,7 @@ bool Manager::RegisterAnalyzerForMIMEType(Tag tag, const string& mtype) TagSet* l = LookupMIMEType(mtype, true); DBG_LOG(DBG_FILE_ANALYSIS, "Register analyzer %s for MIME type %s", - GetComponentName(tag), mtype.c_str()); + GetComponentName(tag).c_str(), mtype.c_str()); l->insert(tag); return true; @@ -466,7 +466,7 @@ bool Manager::UnregisterAnalyzerForMIMEType(Tag tag, const string& mtype) TagSet* l = LookupMIMEType(mtype, true); DBG_LOG(DBG_FILE_ANALYSIS, "Unregister analyzer %s for MIME type %s", - GetComponentName(tag), mtype.c_str()); + GetComponentName(tag).c_str(), mtype.c_str()); l->erase(tag); return true; diff --git a/src/plugin/Component.cc b/src/plugin/Component.cc index ee18d55cdf..a3d2eef194 100644 --- a/src/plugin/Component.cc +++ b/src/plugin/Component.cc @@ -7,15 +7,21 @@ using namespace plugin; -Component::Component(component::Type arg_type) +Component::Component(component::Type arg_type, const std::string& arg_name) { type = arg_type; + name = arg_name; } Component::~Component() { } +const std::string& Component::Name() const + { + return name; + } + component::Type Component::Type() const { return type; @@ -51,4 +57,8 @@ void Component::Describe(ODesc* d) const d->Add("]"); d->Add(" "); + d->Add(name); + d->Add(" ("); + DoDescribe(d); + d->Add(")"); } diff --git a/src/plugin/Component.h b/src/plugin/Component.h index ad02dc7e4b..0b6b5e9c49 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -3,6 +3,8 @@ #ifndef PLUGIN_COMPONENT_H #define PLUGIN_COMPONENT_H +#include + class ODesc; namespace plugin { @@ -32,8 +34,11 @@ public: * Constructor. * * @param type The type of the compoment. + * + * @param name A descriptive name for the component. This name must + * be unique across all components of the same type. */ - Component(component::Type type); + Component(component::Type type, const std::string& name); /** * Destructor. @@ -46,22 +51,37 @@ public: component::Type Type() const; /** - * Returns a descriptive name for the analyzer. This name must be - * unique across all components of the same type. + * Returns the compoment's name. */ - virtual const char* Name() const = 0; + const std::string& Name() const; /** - * Returns a textual representation of the component. The default - * version just output the type. Derived version should call the - * parent's implementation and that add further information. + * Returns a textual representation of the component. This goes into + * the output of "bro -NN". + * + * By default version, this just outputs the type and the name. + * Derived versions should override DoDescribe() to add type specific + * details. * * @param d The description object to use. */ virtual void Describe(ODesc* d) const; +protected: + /** + * Adds type specific information to the outout of Describe(). + * + * @param d The description object to use. + */ + virtual void DoDescribe(ODesc* d) const { } + private: + // Disable. + Component(const Component& other); + Component operator=(const Component& other); + component::Type type; + std::string name; }; } diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 71994d82d1..b3ad944bec 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -37,7 +37,7 @@ public: /** * @return The script-layer module in which the component's "Tag" ID lives. */ - const char* GetModule() const; + const std::string& GetModule() const; /** * @return A list of all registered components. @@ -55,7 +55,7 @@ public: * @param tag A component's tag. * @return The canonical component name. */ - const char* GetComponentName(T tag) const; + const std::string& GetComponentName(T tag) const; /** * Get a component name from it's enum value. @@ -63,7 +63,7 @@ public: * @param val A component's enum value. * @return The canonical component name. */ - const char* GetComponentName(Val* val) const; + const std::string& GetComponentName(Val* val) const; /** * Get a component tag from its name. @@ -134,7 +134,7 @@ ComponentManager::ComponentManager(const string& arg_module) } template -const char* ComponentManager::GetModule() const +const std::string& ComponentManager::GetModule() const { return module.c_str(); } @@ -158,9 +158,9 @@ EnumType* ComponentManager::GetTagEnumType() const } template -const char* ComponentManager::GetComponentName(T tag) const +const std::string& ComponentManager::GetComponentName(T tag) const { - static const char* error = ""; + static const std::string& error = ""; if ( ! tag ) return error; @@ -176,7 +176,7 @@ const char* ComponentManager::GetComponentName(T tag) const } template -const char* ComponentManager::GetComponentName(Val* val) const +const std::string& ComponentManager::GetComponentName(Val* val) const { return GetComponentName(T(val->AsEnumVal())); } @@ -222,14 +222,14 @@ template void ComponentManager::RegisterComponent(C* component, const string& prefix) { - const char* cname = component->CanonicalName(); + std::string cname = component->CanonicalName(); if ( Lookup(cname) ) reporter->FatalError("Component '%s::%s' defined more than once", - module.c_str(), cname); + module.c_str(), cname.c_str()); DBG_LOG(DBG_PLUGINS, "Registering component %s (tag %s)", - component->Name(), component->Tag().AsString().c_str()); + component->Name().c_str(), component->Tag().AsString().c_str()); components_by_name.insert(std::make_pair(cname, component)); components_by_tag.insert(std::make_pair(component->Tag(), component)); @@ -237,7 +237,7 @@ void ComponentManager::RegisterComponent(C* component, component->Tag().AsEnumVal()->InternalInt(), component)); // Install an identfier for enum value - string id = fmt("%s%s", prefix.c_str(), cname); + string id = fmt("%s%s", prefix.c_str(), cname.c_str()); tag_enum_type->AddName(module, id.c_str(), component->Tag().AsEnumVal()->InternalInt(), true); } diff --git a/src/plugin/TaggedComponent.h b/src/plugin/TaggedComponent.h index 99eab9f230..7e3ee24bdf 100644 --- a/src/plugin/TaggedComponent.h +++ b/src/plugin/TaggedComponent.h @@ -23,28 +23,12 @@ public: */ TaggedComponent(typename T::subtype_t subtype = 0); - /** - * Copy constructor. - * - * @param other Another component from which to copy its tag value. - */ - TaggedComponent(const TaggedComponent& other); - - /** - * Assignment operator. - * - * @param other A component to assign. - * @return The assigned object. - */ - TaggedComponent& operator=(const TaggedComponent& other); - /** * @return The component's tag. */ T Tag() const; private: - T tag; /**< The automatically assigned analyzer tag. */ static typename T::type_t type_counter; /**< Used to generate globally unique tags. */ @@ -56,22 +40,6 @@ TaggedComponent::TaggedComponent(typename T::subtype_t subtype) tag = T(++type_counter, subtype); } -template -TaggedComponent::TaggedComponent(const TaggedComponent& other) - { - tag = other.tag; - } - -template -TaggedComponent& -TaggedComponent::operator =(const TaggedComponent& other) - { - if ( &other != this ) - tag = other.tag; - - return *this; - } - template T TaggedComponent::Tag() const { diff --git a/src/util.cc b/src/util.cc index 3b917495bc..e41925a414 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1701,17 +1701,16 @@ const char* bro_magic_buffer(magic_t cookie, const void* buffer, size_t length) return rval; } -const char* canonify_name(const char* name) +std::string canonify_name(const std::string& name) { - unsigned int len = strlen(name); - char* nname = new char[len + 1]; + unsigned int len = name.size(); + std::string nname; for ( unsigned int i = 0; i < len; i++ ) { char c = isalnum(name[i]) ? name[i] : '_'; - nname[i] = toupper(c); + nname += toupper(c); } - nname[len] = '\0'; return nname; } diff --git a/src/util.h b/src/util.h index 8526ded03f..e8bce8221d 100644 --- a/src/util.h +++ b/src/util.h @@ -406,6 +406,6 @@ const char* bro_magic_buffer(magic_t cookie, const void* buffer, size_t length); * @param name The string to canonicalize. * @return The canonicalized version of \a name which caller may later delete[]. */ -const char* canonify_name(const char* name); +std::string canonify_name(const std::string& name); #endif