mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Clean up iterator usage in Analyzer
This commit is contained in:
parent
c9c0fea8d0
commit
44f558df7b
3 changed files with 31 additions and 34 deletions
|
@ -301,17 +301,17 @@ void Analyzer::ForwardPacket(int len, const u_char* data, bool is_orig,
|
|||
AppendNewChildren();
|
||||
|
||||
// Pass to all children.
|
||||
analyzer_list::iterator next;
|
||||
for ( analyzer_list::iterator i = children.begin();
|
||||
i != children.end(); i = next )
|
||||
for ( auto i = children.begin(); i != children.end(); )
|
||||
{
|
||||
Analyzer* current = *i;
|
||||
next = ++i;
|
||||
|
||||
if ( ! (current->finished || current->removing ) )
|
||||
{
|
||||
current->NextPacket(len, data, is_orig, seq, ip, caplen);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
DeleteChild(--i);
|
||||
i = DeleteChild(i);
|
||||
}
|
||||
|
||||
AppendNewChildren();
|
||||
|
@ -324,17 +324,17 @@ void Analyzer::ForwardStream(int len, const u_char* data, bool is_orig)
|
|||
|
||||
AppendNewChildren();
|
||||
|
||||
analyzer_list::iterator next;
|
||||
for ( analyzer_list::iterator i = children.begin();
|
||||
i != children.end(); i = next )
|
||||
for ( auto i = children.begin(); i != children.end(); )
|
||||
{
|
||||
Analyzer* current = *i;
|
||||
next = ++i;
|
||||
|
||||
if ( ! (current->finished || current->removing ) )
|
||||
{
|
||||
current->NextStream(len, data, is_orig);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
DeleteChild(--i);
|
||||
i = DeleteChild(i);
|
||||
}
|
||||
|
||||
AppendNewChildren();
|
||||
|
@ -347,17 +347,17 @@ void Analyzer::ForwardUndelivered(uint64_t seq, int len, bool is_orig)
|
|||
|
||||
AppendNewChildren();
|
||||
|
||||
analyzer_list::iterator next;
|
||||
for ( analyzer_list::iterator i = children.begin();
|
||||
i != children.end(); i = next )
|
||||
for ( auto i = children.begin(); i != children.end(); )
|
||||
{
|
||||
Analyzer* current = *i;
|
||||
next = ++i;
|
||||
|
||||
if ( ! (current->finished || current->removing ) )
|
||||
{
|
||||
current->NextUndelivered(seq, len, is_orig);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
DeleteChild(--i);
|
||||
i = DeleteChild(i);
|
||||
}
|
||||
|
||||
AppendNewChildren();
|
||||
|
@ -367,17 +367,17 @@ void Analyzer::ForwardEndOfData(bool orig)
|
|||
{
|
||||
AppendNewChildren();
|
||||
|
||||
analyzer_list::iterator next;
|
||||
for ( analyzer_list::iterator i = children.begin();
|
||||
i != children.end(); i = next )
|
||||
for ( auto i = children.begin(); i != children.end(); )
|
||||
{
|
||||
Analyzer* current = *i;
|
||||
next = ++i;
|
||||
|
||||
if ( ! (current->finished || current->removing ) )
|
||||
{
|
||||
current->NextEndOfData(orig);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
DeleteChild(--i);
|
||||
i = DeleteChild(i);
|
||||
}
|
||||
|
||||
AppendNewChildren();
|
||||
|
@ -541,7 +541,7 @@ Analyzer* Analyzer::FindChild(const char* name)
|
|||
return tag ? FindChild(tag) : nullptr;
|
||||
}
|
||||
|
||||
void Analyzer::DeleteChild(analyzer_list::iterator i)
|
||||
analyzer_list::iterator Analyzer::DeleteChild(analyzer_list::iterator i)
|
||||
{
|
||||
Analyzer* child = *i;
|
||||
|
||||
|
@ -557,8 +557,9 @@ void Analyzer::DeleteChild(analyzer_list::iterator i)
|
|||
DBG_LOG(DBG_ANALYZER, "%s deleted child %s 3",
|
||||
fmt_analyzer(this).c_str(), fmt_analyzer(child).c_str());
|
||||
|
||||
children.erase(i);
|
||||
auto next = children.erase(i);
|
||||
delete child;
|
||||
return next;
|
||||
}
|
||||
|
||||
void Analyzer::AddSupportAnalyzer(SupportAnalyzer* analyzer)
|
||||
|
|
|
@ -38,7 +38,7 @@ class AnalyzerTimer;
|
|||
class SupportAnalyzer;
|
||||
class OutputHandler;
|
||||
|
||||
using analyzer_list = std::list<Analyzer*>;
|
||||
using analyzer_list = std::vector<Analyzer*>;
|
||||
typedef uint32_t ID;
|
||||
typedef void (Analyzer::*analyzer_timer_func)(double t);
|
||||
|
||||
|
@ -685,8 +685,9 @@ protected:
|
|||
|
||||
private:
|
||||
// Internal method to eventually delete a child analyzer that's
|
||||
// already Done().
|
||||
void DeleteChild(analyzer_list::iterator i);
|
||||
// already Done(). Returns an iterator to the next element, following
|
||||
// std::list::erase()'s semantics.
|
||||
analyzer_list::iterator DeleteChild(analyzer_list::iterator i);
|
||||
|
||||
// Helper for the ctors.
|
||||
void CtorInit(const Tag& tag, Connection* conn);
|
||||
|
@ -727,31 +728,27 @@ private:
|
|||
* Internal convenience macro to iterate over the list of child analyzers.
|
||||
*/
|
||||
#define LOOP_OVER_CHILDREN(var) \
|
||||
for ( zeek::analyzer::analyzer_list::iterator var = children.begin(); \
|
||||
var != children.end(); var++ )
|
||||
for ( auto var = children.begin(); var != children.end(); ++var )
|
||||
|
||||
/**
|
||||
* Internal convenience macro to iterate over the constant list of child
|
||||
* analyzers.
|
||||
*/
|
||||
#define LOOP_OVER_CONST_CHILDREN(var) \
|
||||
for ( zeek::analyzer::analyzer_list::const_iterator var = children.begin(); \
|
||||
var != children.end(); var++ )
|
||||
for ( auto var = children.cbegin(); var != children.cend(); ++var )
|
||||
|
||||
/**
|
||||
* Convenience macro to iterate over a given list of child analyzers.
|
||||
*/
|
||||
#define LOOP_OVER_GIVEN_CHILDREN(var, the_kids) \
|
||||
for ( zeek::analyzer::analyzer_list::iterator var = the_kids.begin(); \
|
||||
var != the_kids.end(); var++ )
|
||||
for ( auto var = the_kids.begin(); var != the_kids.end(); ++var )
|
||||
|
||||
/**
|
||||
* Convenience macro to iterate over a given constant list of child
|
||||
* analyzers.
|
||||
*/
|
||||
#define LOOP_OVER_GIVEN_CONST_CHILDREN(var, the_kids) \
|
||||
for ( zeek::analyzer::analyzer_list::const_iterator var = the_kids.begin(); \
|
||||
var != the_kids.end(); var++ )
|
||||
for ( auto var = the_kids.cbegin(); var != the_kids.cend(); ++var )
|
||||
|
||||
/**
|
||||
* Support analyzer preprocess input before it reaches an analyzer's main
|
||||
|
|
|
@ -174,7 +174,6 @@ private:
|
|||
TCP_Endpoint* orig;
|
||||
TCP_Endpoint* resp;
|
||||
|
||||
using analyzer_list = std::list<analyzer::Analyzer*>;
|
||||
analyzer_list packet_children;
|
||||
|
||||
unsigned int first_packet_seen: 2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue