From d727af097b2d78a77c85d98903278a1c1dbdc4ab Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Tue, 26 Nov 2013 11:22:23 -0800 Subject: [PATCH] Minor API changes to analyzers. --- src/analyzer/Analyzer.cc | 4 ++-- src/analyzer/Analyzer.h | 9 ++++++--- src/analyzer/Component.cc | 4 ++++ src/analyzer/Manager.cc | 10 +++++----- src/analyzer/Manager.h | 8 ++++++++ src/analyzer/protocol/tcp/TCP.h | 4 ++-- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index 03734f1a22..2927e3ad97 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -644,12 +644,12 @@ void Analyzer::FlipRoles() resp_supporters = tmp; } -void Analyzer::ProtocolConfirmation() +void Analyzer::ProtocolConfirmation(Tag arg_tag) { if ( protocol_confirmed ) return; - EnumVal* tval = tag.AsEnumVal(); + EnumVal* tval = arg_tag ? arg_tag.AsEnumVal() : tag.AsEnumVal(); Ref(tval); val_list* vl = new val_list; diff --git a/src/analyzer/Analyzer.h b/src/analyzer/Analyzer.h index f7ca07ca51..eec0303475 100644 --- a/src/analyzer/Analyzer.h +++ b/src/analyzer/Analyzer.h @@ -97,8 +97,8 @@ public: /** * Constructor. As this version of the constructor does not receive a - * name or tag, setTag() must be called before the instance can be - * used. + * name or tag, SetAnalyzerTag() must be called before the instance + * can be used. * * @param conn The connection the analyzer is associated with. */ @@ -471,8 +471,11 @@ public: * may turn into \c protocol_confirmed event at the script-layer (but * only once per analyzer for each connection, even if the method is * called multiple times). + * + * If tag is given, it overrides the analyzer tag passed to the + * scripting layer; the default is the one of the analyzer itself. */ - virtual void ProtocolConfirmation(); + virtual void ProtocolConfirmation(Tag tag = Tag()); /** * Signals Bro's protocol detection that the analyzer has found a diff --git a/src/analyzer/Component.cc b/src/analyzer/Component.cc index 66ab2213bb..255e03435c 100644 --- a/src/analyzer/Component.cc +++ b/src/analyzer/Component.cc @@ -17,6 +17,8 @@ Component::Component(const char* arg_name, factory_callback arg_factory, Tag::su factory = arg_factory; enabled = arg_enabled; partial = arg_partial; + + analyzer_mgr->RegisterComponent(this, "ANALYZER_"); } Component::Component(const Component& other) @@ -28,6 +30,8 @@ Component::Component(const Component& other) factory = other.factory; enabled = other.enabled; partial = other.partial; + + // TODO: Do we need the RegisterComponent() call here? } Component::~Component() diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 6268fde177..748af34dfb 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -86,11 +86,6 @@ Manager::~Manager() void Manager::InitPreScript() { - std::list analyzers = plugin_mgr->Components(); - - for ( std::list::const_iterator i = analyzers.begin(); i != analyzers.end(); i++ ) - RegisterComponent(*i, "ANALYZER_"); - // Cache these tags. analyzer_backdoor = GetComponentTag("BACKDOOR"); analyzer_connsize = GetComponentTag("CONNSIZE"); @@ -202,6 +197,11 @@ void Manager::DisableAllAnalyzers() (*i)->SetEnabled(false); } +analyzer::Tag Manager::GetAnalyzerTag(const char* name) + { + return GetComponentTag(name); + } + bool Manager::IsEnabled(Tag tag) { if ( ! tag ) diff --git a/src/analyzer/Manager.h b/src/analyzer/Manager.h index 77b40a1d68..c842794d6c 100644 --- a/src/analyzer/Manager.h +++ b/src/analyzer/Manager.h @@ -133,6 +133,14 @@ public: */ void DisableAllAnalyzers(); + /** + * Returns the tag associated with an analyer name, or the tag + * associated with an error if no such analyzer exists. + * + * @param name The canonical analyzer name to check. + */ + Tag GetAnalyzerTag(const char* name); + /** * Returns true if an analyzer is enabled. * diff --git a/src/analyzer/protocol/tcp/TCP.h b/src/analyzer/protocol/tcp/TCP.h index b2649b4ab8..e01ed3a255 100644 --- a/src/analyzer/protocol/tcp/TCP.h +++ b/src/analyzer/protocol/tcp/TCP.h @@ -294,8 +294,8 @@ public: // TCP_ENDPOINT_RESET. If gen_event is true and the connection // is now fully closed, a connection_finished event will be // generated; otherwise not. - virtual void ConnectionClosed(TCP_Endpoint* endpoint, - TCP_Endpoint* peer, int gen_event); + virtual void ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint, + analyzer::tcp::TCP_Endpoint* peer, int gen_event); virtual void ConnectionFinished(int half_finished); virtual void ConnectionReset();