mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/timw/easy-pdict-replacements'
* origin/topic/timw/easy-pdict-replacements: Cleanups related to PDict -> std::map replacements Remove other simple uses of PDict Protocols: Remove uses of PDict g_dbgfilemaps: Remove uses of PDict Scope: remove uses of PDict DFA: remove uses of PDict EventRegistry: remove uses of PDict
This commit is contained in:
commit
94c380297e
37 changed files with 275 additions and 298 deletions
6
CHANGES
6
CHANGES
|
@ -1,4 +1,10 @@
|
||||||
|
|
||||||
|
3.1.0-dev.48 | 2019-08-13 20:15:17 -0700
|
||||||
|
|
||||||
|
* Cleanups related to PDict -> std::map replacements (Jon Siwek, Corelight)
|
||||||
|
|
||||||
|
* Replace various uses of PDict with std::map (Tim Wojtulewicz, Corelight)
|
||||||
|
|
||||||
3.1.0-dev.40 | 2019-08-13 23:44:45 +0000
|
3.1.0-dev.40 | 2019-08-13 23:44:45 +0000
|
||||||
|
|
||||||
* Change over to whitelisting clang-tidy options instead of
|
* Change over to whitelisting clang-tidy options instead of
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
3.1.0-dev.40
|
3.1.0-dev.48
|
||||||
|
|
77
src/DFA.cc
77
src/DFA.cc
|
@ -17,7 +17,6 @@ DFA_State::DFA_State(int arg_state_num, const EquivClass* ec,
|
||||||
nfa_states = arg_nfa_states;
|
nfa_states = arg_nfa_states;
|
||||||
accept = arg_accept;
|
accept = arg_accept;
|
||||||
mark = 0;
|
mark = 0;
|
||||||
centry = 0;
|
|
||||||
|
|
||||||
SymPartition(ec);
|
SymPartition(ec);
|
||||||
|
|
||||||
|
@ -285,8 +284,7 @@ unsigned int DFA_State::Size()
|
||||||
+ pad_size(sizeof(DFA_State*) * num_sym)
|
+ pad_size(sizeof(DFA_State*) * num_sym)
|
||||||
+ (accept ? pad_size(sizeof(int) * accept->size()) : 0)
|
+ (accept ? pad_size(sizeof(int) * accept->size()) : 0)
|
||||||
+ (nfa_states ? pad_size(sizeof(NFA_State*) * nfa_states->length()) : 0)
|
+ (nfa_states ? pad_size(sizeof(NFA_State*) * nfa_states->length()) : 0)
|
||||||
+ (meta_ec ? meta_ec->Size() : 0)
|
+ (meta_ec ? meta_ec->Size() : 0);
|
||||||
+ (centry ? padded_sizeof(CacheEntry) : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DFA_State_Cache::DFA_State_Cache()
|
DFA_State_Cache::DFA_State_Cache()
|
||||||
|
@ -296,19 +294,16 @@ DFA_State_Cache::DFA_State_Cache()
|
||||||
|
|
||||||
DFA_State_Cache::~DFA_State_Cache()
|
DFA_State_Cache::~DFA_State_Cache()
|
||||||
{
|
{
|
||||||
IterCookie* i = states.InitForIteration();
|
for ( auto& entry : states )
|
||||||
CacheEntry* e;
|
|
||||||
while ( (e = (CacheEntry*) states.NextEntry(i)) )
|
|
||||||
{
|
{
|
||||||
assert(e->state);
|
assert(entry.second);
|
||||||
delete e->hash;
|
Unref(entry.second);
|
||||||
Unref(e->state);
|
|
||||||
delete e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
states.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas,
|
DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas, DigestStr* digest)
|
||||||
HashKey** hash)
|
|
||||||
{
|
{
|
||||||
// We assume that state ID's don't exceed 10 digits, plus
|
// We assume that state ID's don't exceed 10 digits, plus
|
||||||
// we allow one more character for the delimiter.
|
// we allow one more character for the delimiter.
|
||||||
|
@ -335,37 +330,27 @@ DFA_State* DFA_State_Cache::Lookup(const NFA_state_list& nfas,
|
||||||
|
|
||||||
// We use the short MD5 instead of the full string for the
|
// We use the short MD5 instead of the full string for the
|
||||||
// HashKey because the data is copied into the key.
|
// HashKey because the data is copied into the key.
|
||||||
u_char digest[16];
|
u_char digest_bytes[16];
|
||||||
internal_md5(id_tag, p - id_tag, digest);
|
internal_md5(id_tag, p - id_tag, digest_bytes);
|
||||||
|
*digest = DigestStr(digest_bytes, 16);
|
||||||
|
|
||||||
*hash = new HashKey(&digest, sizeof(digest));
|
auto entry = states.find(*digest);
|
||||||
CacheEntry* e = states.Lookup(*hash);
|
if ( entry == states.end() )
|
||||||
if ( ! e )
|
|
||||||
{
|
{
|
||||||
++misses;
|
++misses;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
++hits;
|
++hits;
|
||||||
|
|
||||||
delete *hash;
|
digest->clear();
|
||||||
*hash = 0;
|
|
||||||
|
|
||||||
return e->state;
|
return entry->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
DFA_State* DFA_State_Cache::Insert(DFA_State* state, HashKey* hash)
|
DFA_State* DFA_State_Cache::Insert(DFA_State* state, DigestStr digest)
|
||||||
{
|
{
|
||||||
CacheEntry* e;
|
states.emplace(std::move(digest), state);
|
||||||
|
return state;
|
||||||
e = new CacheEntry;
|
|
||||||
|
|
||||||
e->state = state;
|
|
||||||
e->state->centry = e;
|
|
||||||
e->hash = hash;
|
|
||||||
|
|
||||||
states.Insert(hash, e);
|
|
||||||
|
|
||||||
return e->state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DFA_State_Cache::GetStats(Stats* s)
|
void DFA_State_Cache::GetStats(Stats* s)
|
||||||
|
@ -378,15 +363,13 @@ void DFA_State_Cache::GetStats(Stats* s)
|
||||||
s->hits = hits;
|
s->hits = hits;
|
||||||
s->misses = misses;
|
s->misses = misses;
|
||||||
|
|
||||||
CacheEntry* e;
|
for ( const auto& state : states )
|
||||||
|
|
||||||
IterCookie* i = states.InitForIteration();
|
|
||||||
while ( (e = (CacheEntry*) states.NextEntry(i)) )
|
|
||||||
{
|
{
|
||||||
|
DFA_State* e = state.second;
|
||||||
++s->dfa_states;
|
++s->dfa_states;
|
||||||
s->nfa_states += e->state->NFAStateNum();
|
s->nfa_states += e->NFAStateNum();
|
||||||
e->state->Stats(&s->computed, &s->uncomputed);
|
e->Stats(&s->computed, &s->uncomputed);
|
||||||
s->mem += pad_size(e->state->Size()) + padded_sizeof(*e->state);
|
s->mem += pad_size(e->Size()) + padded_sizeof(*e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +390,7 @@ DFA_Machine::DFA_Machine(NFA_Machine* n, EquivClass* arg_ec)
|
||||||
if ( ns->length() > 0 )
|
if ( ns->length() > 0 )
|
||||||
{
|
{
|
||||||
NFA_state_list* state_set = epsilon_closure(ns);
|
NFA_state_list* state_set = epsilon_closure(ns);
|
||||||
(void) StateSetToDFA_State(state_set, start_state, ec);
|
StateSetToDFA_State(state_set, start_state, ec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -445,14 +428,14 @@ unsigned int DFA_Machine::MemoryAllocation() const
|
||||||
+ nfa->MemoryAllocation();
|
+ nfa->MemoryAllocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
|
bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
|
||||||
DFA_State*& d, const EquivClass* ec)
|
DFA_State*& d, const EquivClass* ec)
|
||||||
{
|
{
|
||||||
HashKey* hash;
|
DigestStr digest;
|
||||||
d = dfa_state_cache->Lookup(*state_set, &hash);
|
d = dfa_state_cache->Lookup(*state_set, &digest);
|
||||||
|
|
||||||
if ( d )
|
if ( d )
|
||||||
return 0;
|
return false;
|
||||||
|
|
||||||
AcceptingSet* accept = new AcceptingSet;
|
AcceptingSet* accept = new AcceptingSet;
|
||||||
|
|
||||||
|
@ -471,9 +454,9 @@ int DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
|
||||||
}
|
}
|
||||||
|
|
||||||
DFA_State* ds = new DFA_State(state_count++, ec, state_set, accept);
|
DFA_State* ds = new DFA_State(state_count++, ec, state_set, accept);
|
||||||
d = dfa_state_cache->Insert(ds, hash);
|
d = dfa_state_cache->Insert(ds, std::move(digest));
|
||||||
|
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DFA_Machine::Rep(int sym)
|
int DFA_Machine::Rep(int sym)
|
||||||
|
|
20
src/DFA.h
20
src/DFA.h
|
@ -17,7 +17,6 @@ class DFA_State;
|
||||||
|
|
||||||
class DFA_Machine;
|
class DFA_Machine;
|
||||||
class DFA_State;
|
class DFA_State;
|
||||||
struct CacheEntry;
|
|
||||||
|
|
||||||
class DFA_State : public BroObj {
|
class DFA_State : public BroObj {
|
||||||
public:
|
public:
|
||||||
|
@ -64,15 +63,11 @@ protected:
|
||||||
NFA_state_list* nfa_states;
|
NFA_state_list* nfa_states;
|
||||||
EquivClass* meta_ec; // which ec's make same transition
|
EquivClass* meta_ec; // which ec's make same transition
|
||||||
DFA_State* mark;
|
DFA_State* mark;
|
||||||
CacheEntry* centry;
|
|
||||||
|
|
||||||
static unsigned int transition_counter; // see Xtion()
|
static unsigned int transition_counter; // see Xtion()
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CacheEntry {
|
using DigestStr = basic_string<u_char>;
|
||||||
DFA_State* state;
|
|
||||||
HashKey* hash;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DFA_State_Cache {
|
class DFA_State_Cache {
|
||||||
public:
|
public:
|
||||||
|
@ -80,13 +75,12 @@ public:
|
||||||
~DFA_State_Cache();
|
~DFA_State_Cache();
|
||||||
|
|
||||||
// If the caller stores the handle, it has to call Ref() on it.
|
// If the caller stores the handle, it has to call Ref() on it.
|
||||||
DFA_State* Lookup(const NFA_state_list& nfa_states,
|
DFA_State* Lookup(const NFA_state_list& nfa_states, DigestStr* digest);
|
||||||
HashKey** hash);
|
|
||||||
|
|
||||||
// Takes ownership of both; hash is the one returned by Lookup().
|
// Takes ownership of state; digest is the one returned by Lookup().
|
||||||
DFA_State* Insert(DFA_State* state, HashKey* hash);
|
DFA_State* Insert(DFA_State* state, DigestStr digest);
|
||||||
|
|
||||||
int NumEntries() const { return states.Length(); }
|
int NumEntries() const { return states.size(); }
|
||||||
|
|
||||||
struct Stats {
|
struct Stats {
|
||||||
// Sum of all NFA states
|
// Sum of all NFA states
|
||||||
|
@ -106,7 +100,7 @@ private:
|
||||||
int misses;
|
int misses;
|
||||||
|
|
||||||
// Hash indexed by NFA states (MD5s of them, actually).
|
// Hash indexed by NFA states (MD5s of them, actually).
|
||||||
PDict<CacheEntry> states;
|
std::map<DigestStr, DFA_State*> states;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DFA_Machine : public BroObj {
|
class DFA_Machine : public BroObj {
|
||||||
|
@ -134,7 +128,7 @@ protected:
|
||||||
int state_count;
|
int state_count;
|
||||||
|
|
||||||
// The state list has to be sorted according to IDs.
|
// The state list has to be sorted according to IDs.
|
||||||
int StateSetToDFA_State(NFA_state_list* state_set, DFA_State*& d,
|
bool StateSetToDFA_State(NFA_state_list* state_set, DFA_State*& d,
|
||||||
const EquivClass* ec);
|
const EquivClass* ec);
|
||||||
const EquivClass* EC() const { return ec; }
|
const EquivClass* EC() const { return ec; }
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,6 @@ protected:
|
||||||
|
|
||||||
DNS_MgrMode mode;
|
DNS_MgrMode mode;
|
||||||
|
|
||||||
PDict<ListVal> services;
|
|
||||||
|
|
||||||
HostMap host_mappings;
|
HostMap host_mappings;
|
||||||
AddrMap addr_mappings;
|
AddrMap addr_mappings;
|
||||||
TextMap text_mappings;
|
TextMap text_mappings;
|
||||||
|
|
|
@ -27,7 +27,7 @@ using namespace std;
|
||||||
bool g_policy_debug = false;
|
bool g_policy_debug = false;
|
||||||
DebuggerState g_debugger_state;
|
DebuggerState g_debugger_state;
|
||||||
TraceState g_trace_state;
|
TraceState g_trace_state;
|
||||||
PDict<Filemap> g_dbgfilemaps;
|
std::map<string, Filemap*> g_dbgfilemaps;
|
||||||
|
|
||||||
// These variables are used only to decide whether or not to print the
|
// These variables are used only to decide whether or not to print the
|
||||||
// current context; you don't want to do it after a step or next
|
// current context; you don't want to do it after a step or next
|
||||||
|
@ -364,8 +364,8 @@ vector<ParseLocationRec> parse_location_string(const string& s)
|
||||||
|
|
||||||
if ( plr.type == plrFileAndLine )
|
if ( plr.type == plrFileAndLine )
|
||||||
{
|
{
|
||||||
Filemap* map = g_dbgfilemaps.Lookup(loc_filename);
|
auto iter = g_dbgfilemaps.find(loc_filename);
|
||||||
if ( ! map )
|
if ( iter == g_dbgfilemaps.end() )
|
||||||
reporter->InternalError("Policy file %s should have been loaded\n",
|
reporter->InternalError("Policy file %s should have been loaded\n",
|
||||||
loc_filename);
|
loc_filename);
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ vector<ParseLocationRec> parse_location_string(const string& s)
|
||||||
}
|
}
|
||||||
|
|
||||||
StmtLocMapping* hit = 0;
|
StmtLocMapping* hit = 0;
|
||||||
for ( const auto entry : *map )
|
for ( const auto entry : *(iter->second) )
|
||||||
{
|
{
|
||||||
plr.filename = entry->Loc().filename;
|
plr.filename = entry->Loc().filename;
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ string get_context_description(const Stmt* stmt, const Frame* frame);
|
||||||
|
|
||||||
extern Frame* g_dbg_locals; // variables created within debugger context
|
extern Frame* g_dbg_locals; // variables created within debugger context
|
||||||
|
|
||||||
extern PDict<Filemap> g_dbgfilemaps; // filename => filemap
|
extern std::map<string, Filemap*> g_dbgfilemaps; // filename => filemap
|
||||||
|
|
||||||
// Perhaps add a code/priority argument to do selective output.
|
// Perhaps add a code/priority argument to do selective output.
|
||||||
int debug_msg(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
int debug_msg(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||||
|
|
|
@ -51,14 +51,16 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope* global = global_scope();
|
Scope* global = global_scope();
|
||||||
PDict<ID>* syms = global->Vars();
|
const auto& syms = global->Vars();
|
||||||
|
|
||||||
ID* nextid;
|
ID* nextid;
|
||||||
IterCookie* cookie = syms->InitForIteration();
|
for ( const auto& sym : syms )
|
||||||
while ( (nextid = syms->NextEntry( cookie )) )
|
{
|
||||||
|
ID* nextid = sym.second;
|
||||||
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC )
|
if ( ! func_only || nextid->Type()->Tag() == TYPE_FUNC )
|
||||||
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
|
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
|
||||||
matches.push_back(nextid);
|
matches.push_back(nextid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
|
void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
|
||||||
|
|
|
@ -4,85 +4,67 @@
|
||||||
|
|
||||||
void EventRegistry::Register(EventHandlerPtr handler)
|
void EventRegistry::Register(EventHandlerPtr handler)
|
||||||
{
|
{
|
||||||
HashKey key(handler->Name());
|
handlers[string(handler->Name())] = handler.Ptr();
|
||||||
handlers.Insert(&key, handler.Ptr());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler* EventRegistry::Lookup(const char* name)
|
EventHandler* EventRegistry::Lookup(const string& name)
|
||||||
{
|
{
|
||||||
HashKey key(name);
|
auto it = handlers.find(name);
|
||||||
return handlers.Lookup(&key);
|
if ( it != handlers.end() )
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistry::string_list* EventRegistry::Match(RE_Matcher* pattern)
|
EventRegistry::string_list EventRegistry::Match(RE_Matcher* pattern)
|
||||||
{
|
{
|
||||||
string_list* names = new string_list;
|
string_list names;
|
||||||
|
|
||||||
IterCookie* c = handlers.InitForIteration();
|
for ( const auto& entry : handlers )
|
||||||
|
|
||||||
HashKey* k;
|
|
||||||
EventHandler* v;
|
|
||||||
while ( (v = handlers.NextEntry(k, c)) )
|
|
||||||
{
|
{
|
||||||
|
EventHandler* v = entry.second;
|
||||||
if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) )
|
if ( v->LocalHandler() && pattern->MatchExactly(v->Name()) )
|
||||||
names->push_back(v->Name());
|
names.push_back(entry.first);
|
||||||
|
|
||||||
delete k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistry::string_list* EventRegistry::UnusedHandlers()
|
EventRegistry::string_list EventRegistry::UnusedHandlers()
|
||||||
{
|
{
|
||||||
string_list* names = new string_list;
|
string_list names;
|
||||||
|
|
||||||
IterCookie* c = handlers.InitForIteration();
|
for ( const auto& entry : handlers )
|
||||||
|
|
||||||
HashKey* k;
|
|
||||||
EventHandler* v;
|
|
||||||
while ( (v = handlers.NextEntry(k, c)) )
|
|
||||||
{
|
{
|
||||||
|
EventHandler* v = entry.second;
|
||||||
if ( v->LocalHandler() && ! v->Used() )
|
if ( v->LocalHandler() && ! v->Used() )
|
||||||
names->push_back(v->Name());
|
names.push_back(entry.first);
|
||||||
|
|
||||||
delete k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistry::string_list* EventRegistry::UsedHandlers()
|
EventRegistry::string_list EventRegistry::UsedHandlers()
|
||||||
{
|
{
|
||||||
string_list* names = new string_list;
|
string_list names;
|
||||||
|
|
||||||
IterCookie* c = handlers.InitForIteration();
|
for ( const auto& entry : handlers )
|
||||||
|
|
||||||
HashKey* k;
|
|
||||||
EventHandler* v;
|
|
||||||
while ( (v = handlers.NextEntry(k, c)) )
|
|
||||||
{
|
{
|
||||||
|
EventHandler* v = entry.second;
|
||||||
if ( v->LocalHandler() && v->Used() )
|
if ( v->LocalHandler() && v->Used() )
|
||||||
names->push_back(v->Name());
|
names.push_back(entry.first);
|
||||||
|
|
||||||
delete k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventRegistry::string_list* EventRegistry::AllHandlers()
|
EventRegistry::string_list EventRegistry::AllHandlers()
|
||||||
{
|
{
|
||||||
string_list* names = new string_list(handlers.Length());
|
string_list names;
|
||||||
|
|
||||||
IterCookie* c = handlers.InitForIteration();
|
for ( const auto& entry : handlers )
|
||||||
|
|
||||||
HashKey* k;
|
|
||||||
EventHandler* v;
|
|
||||||
while ( (v = handlers.NextEntry(k, c)) )
|
|
||||||
{
|
{
|
||||||
names->push_back(v->Name());
|
names.push_back(entry.first);
|
||||||
delete k;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return names;
|
return names;
|
||||||
|
@ -90,13 +72,9 @@ EventRegistry::string_list* EventRegistry::AllHandlers()
|
||||||
|
|
||||||
void EventRegistry::PrintDebug()
|
void EventRegistry::PrintDebug()
|
||||||
{
|
{
|
||||||
IterCookie* c = handlers.InitForIteration();
|
for ( const auto& entry : handlers )
|
||||||
|
|
||||||
HashKey* k;
|
|
||||||
EventHandler* v;
|
|
||||||
while ( (v = handlers.NextEntry(k, c)) )
|
|
||||||
{
|
{
|
||||||
delete k;
|
EventHandler* v = entry.second;
|
||||||
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
|
fprintf(stderr, "Registered event %s (%s handler / %s)\n", v->Name(),
|
||||||
v->LocalHandler()? "local" : "no",
|
v->LocalHandler()? "local" : "no",
|
||||||
*v ? "active" : "not active"
|
*v ? "active" : "not active"
|
||||||
|
@ -104,7 +82,7 @@ void EventRegistry::PrintDebug()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventRegistry::SetErrorHandler(const char* name)
|
void EventRegistry::SetErrorHandler(const string& name)
|
||||||
{
|
{
|
||||||
EventHandler* eh = Lookup(name);
|
EventHandler* eh = Lookup(name);
|
||||||
|
|
||||||
|
@ -114,7 +92,7 @@ void EventRegistry::SetErrorHandler(const char* name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reporter->InternalWarning(
|
reporter->InternalWarning("unknown event handler '%s' in SetErrorHandler()",
|
||||||
"unknown event handler '%s' in SetErrorHandler()", name);
|
name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
#ifndef EVENT_REGISTRY
|
#ifndef EVENT_REGISTRY
|
||||||
#define EVENT_REGISTRY
|
#define EVENT_REGISTRY
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Func.h"
|
#include "Func.h"
|
||||||
#include "List.h"
|
#include "List.h"
|
||||||
#include "Dict.h"
|
#include "Dict.h"
|
||||||
|
@ -17,28 +20,26 @@ public:
|
||||||
void Register(EventHandlerPtr handler);
|
void Register(EventHandlerPtr handler);
|
||||||
|
|
||||||
// Return nil if unknown.
|
// Return nil if unknown.
|
||||||
EventHandler* Lookup(const char* name);
|
EventHandler* Lookup(const string& name);
|
||||||
|
|
||||||
// Returns a list of all local handlers that match the given pattern.
|
// Returns a list of all local handlers that match the given pattern.
|
||||||
// Passes ownership of list.
|
// Passes ownership of list.
|
||||||
typedef const char constchar; // PList doesn't like "const char"
|
typedef vector<string> string_list;
|
||||||
typedef PList<constchar> string_list;
|
string_list Match(RE_Matcher* pattern);
|
||||||
string_list* Match(RE_Matcher* pattern);
|
|
||||||
|
|
||||||
// Marks a handler as handling errors. Error handler will not be called
|
// Marks a handler as handling errors. Error handler will not be called
|
||||||
// recursively to avoid infinite loops in case they trigger an error
|
// recursively to avoid infinite loops in case they trigger an error
|
||||||
// themselves.
|
// themselves.
|
||||||
void SetErrorHandler(const char* name);
|
void SetErrorHandler(const string& name);
|
||||||
|
|
||||||
string_list* UnusedHandlers();
|
string_list UnusedHandlers();
|
||||||
string_list* UsedHandlers();
|
string_list UsedHandlers();
|
||||||
string_list* AllHandlers();
|
string_list AllHandlers();
|
||||||
|
|
||||||
void PrintDebug();
|
void PrintDebug();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef PDict<EventHandler> handler_map;
|
std::map<std::string, EventHandler*> handlers;
|
||||||
handler_map handlers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern EventRegistry* event_registry;
|
extern EventRegistry* event_registry;
|
||||||
|
|
|
@ -4347,7 +4347,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
|
||||||
|
|
||||||
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
||||||
auto fullname = make_full_var_name(current_module.data(), my_name.data());
|
auto fullname = make_full_var_name(current_module.data(), my_name.data());
|
||||||
auto id = global_scope()->Lookup(fullname.data());
|
auto id = global_scope()->Lookup(fullname);
|
||||||
|
|
||||||
if ( id )
|
if ( id )
|
||||||
// Just try again to make a unique lambda name. If two peer
|
// Just try again to make a unique lambda name. If two peer
|
||||||
|
@ -4413,7 +4413,7 @@ EventExpr::EventExpr(const char* arg_name, ListExpr* arg_args)
|
||||||
name = arg_name;
|
name = arg_name;
|
||||||
args = arg_args;
|
args = arg_args;
|
||||||
|
|
||||||
EventHandler* h = event_registry->Lookup(name.c_str());
|
EventHandler* h = event_registry->Lookup(name);
|
||||||
if ( ! h )
|
if ( ! h )
|
||||||
{
|
{
|
||||||
h = new EventHandler(name.c_str());
|
h = new EventHandler(name.c_str());
|
||||||
|
|
|
@ -122,7 +122,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
|
||||||
if ( ! name )
|
if ( ! name )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
ID* id = global_scope()->Lookup(name->c_str());
|
ID* id = global_scope()->Lookup(*name);
|
||||||
if ( ! id )
|
if ( ! id )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
|
23
src/RE.cc
23
src/RE.cc
|
@ -194,9 +194,13 @@ int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Specific_RE_Matcher::LookupDef(const char* def)
|
string Specific_RE_Matcher::LookupDef(const string& def)
|
||||||
{
|
{
|
||||||
return defs.Lookup(def);
|
const auto& iter = defs.find(def);
|
||||||
|
if ( iter != defs.end() )
|
||||||
|
return iter->second;
|
||||||
|
|
||||||
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Specific_RE_Matcher::MatchAll(const char* s)
|
int Specific_RE_Matcher::MatchAll(const char* s)
|
||||||
|
@ -412,10 +416,21 @@ unsigned int Specific_RE_Matcher::MemoryAllocation() const
|
||||||
for ( int i = 0; i < ccl_list.length(); ++i )
|
for ( int i = 0; i < ccl_list.length(); ++i )
|
||||||
size += ccl_list[i]->MemoryAllocation();
|
size += ccl_list[i]->MemoryAllocation();
|
||||||
|
|
||||||
|
size += pad_size(sizeof(CCL*) * ccl_dict.size());
|
||||||
|
for ( const auto& entry : ccl_dict )
|
||||||
|
{
|
||||||
|
size += padded_sizeof(std::string) + pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||||
|
size += entry.second->MemoryAllocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( const auto& entry : defs )
|
||||||
|
{
|
||||||
|
size += padded_sizeof(std::string) + pad_size(sizeof(std::string::value_type) * entry.first.size());
|
||||||
|
size += padded_sizeof(std::string) + pad_size(sizeof(std::string::value_type) * entry.second.size());
|
||||||
|
}
|
||||||
|
|
||||||
return size + padded_sizeof(*this)
|
return size + padded_sizeof(*this)
|
||||||
+ (pattern_text ? pad_size(strlen(pattern_text) + 1) : 0)
|
+ (pattern_text ? pad_size(strlen(pattern_text) + 1) : 0)
|
||||||
+ defs.MemoryAllocation() - padded_sizeof(defs) // FIXME: count content
|
|
||||||
+ ccl_dict.MemoryAllocation() - padded_sizeof(ccl_dict) // FIXME: count content
|
|
||||||
+ ccl_list.MemoryAllocation() - padded_sizeof(ccl_list)
|
+ ccl_list.MemoryAllocation() - padded_sizeof(ccl_list)
|
||||||
+ equiv_class.Size() - padded_sizeof(EquivClass)
|
+ equiv_class.Size() - padded_sizeof(EquivClass)
|
||||||
+ (dfa ? dfa->MemoryAllocation() : 0) // this is ref counted; consider the bytes here?
|
+ (dfa ? dfa->MemoryAllocation() : 0) // this is ref counted; consider the bytes here?
|
||||||
|
|
17
src/RE.h
17
src/RE.h
|
@ -59,15 +59,22 @@ public:
|
||||||
// The following is vestigial from flex's use of "{name}" definitions.
|
// The following is vestigial from flex's use of "{name}" definitions.
|
||||||
// It's here because at some point we may want to support such
|
// It's here because at some point we may want to support such
|
||||||
// functionality.
|
// functionality.
|
||||||
const char* LookupDef(const char* def);
|
std::string LookupDef(const std::string& def);
|
||||||
|
|
||||||
void InsertCCL(const char* txt, CCL* ccl) { ccl_dict.Insert(txt, ccl); }
|
void InsertCCL(const char* txt, CCL* ccl) { ccl_dict[string(txt)] = ccl; }
|
||||||
int InsertCCL(CCL* ccl)
|
int InsertCCL(CCL* ccl)
|
||||||
{
|
{
|
||||||
ccl_list.push_back(ccl);
|
ccl_list.push_back(ccl);
|
||||||
return ccl_list.length() - 1;
|
return ccl_list.length() - 1;
|
||||||
}
|
}
|
||||||
CCL* LookupCCL(const char* txt) { return ccl_dict.Lookup(txt); }
|
CCL* LookupCCL(const char* txt)
|
||||||
|
{
|
||||||
|
const auto& iter = ccl_dict.find(string(txt));
|
||||||
|
if ( iter != ccl_dict.end() )
|
||||||
|
return iter->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
CCL* LookupCCL(int index) { return ccl_list[index]; }
|
CCL* LookupCCL(int index) { return ccl_list[index]; }
|
||||||
CCL* AnyCCL();
|
CCL* AnyCCL();
|
||||||
|
|
||||||
|
@ -119,8 +126,8 @@ protected:
|
||||||
int multiline;
|
int multiline;
|
||||||
char* pattern_text;
|
char* pattern_text;
|
||||||
|
|
||||||
PDict<char> defs;
|
std::map<string, string> defs;
|
||||||
PDict<CCL> ccl_dict;
|
std::map<string, CCL*> ccl_dict;
|
||||||
PList<CCL> ccl_list;
|
PList<CCL> ccl_list;
|
||||||
EquivClass equiv_class;
|
EquivClass equiv_class;
|
||||||
int* ecs;
|
int* ecs;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define rule_h
|
#define rule_h
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "Obj.h"
|
#include "Obj.h"
|
||||||
#include "List.h"
|
#include "List.h"
|
||||||
|
@ -15,7 +16,7 @@ class RuleHdrTest;
|
||||||
class Rule;
|
class Rule;
|
||||||
|
|
||||||
typedef PList<Rule> rule_list;
|
typedef PList<Rule> rule_list;
|
||||||
typedef PDict<Rule> rule_dict;
|
typedef std::map<string, Rule*> rule_dict;
|
||||||
|
|
||||||
class Rule {
|
class Rule {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -267,14 +267,14 @@ bool RuleMatcher::ReadFiles(const name_list& files)
|
||||||
|
|
||||||
void RuleMatcher::AddRule(Rule* rule)
|
void RuleMatcher::AddRule(Rule* rule)
|
||||||
{
|
{
|
||||||
if ( rules_by_id.Lookup(rule->ID()) )
|
if ( rules_by_id.find(rule->ID()) != rules_by_id.end() )
|
||||||
{
|
{
|
||||||
rules_error("rule defined twice");
|
rules_error("rule defined twice");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rules.push_back(rule);
|
rules.push_back(rule);
|
||||||
rules_by_id.Insert(rule->ID(), rule);
|
rules_by_id[rule->ID()] = rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RuleMatcher::BuildRulesTree()
|
void RuleMatcher::BuildRulesTree()
|
||||||
|
@ -295,15 +295,15 @@ void RuleMatcher::InsertRuleIntoTree(Rule* r, int testnr,
|
||||||
// Initiliaze the preconditions
|
// Initiliaze the preconditions
|
||||||
for ( const auto& pc : r->preconds )
|
for ( const auto& pc : r->preconds )
|
||||||
{
|
{
|
||||||
Rule* pc_rule = rules_by_id.Lookup(pc->id);
|
auto entry = rules_by_id.find(pc->id);
|
||||||
if ( ! pc_rule )
|
if ( entry == rules_by_id.end() )
|
||||||
{
|
{
|
||||||
rules_error(r, "unknown rule referenced");
|
rules_error(r, "unknown rule referenced");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pc->rule = pc_rule;
|
pc->rule = entry->second;
|
||||||
pc_rule->dependents.push_back(r);
|
entry->second->dependents.push_back(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All tests in tree already?
|
// All tests in tree already?
|
||||||
|
|
24
src/Scope.cc
24
src/Scope.cc
|
@ -19,7 +19,6 @@ Scope::Scope(ID* id, attr_list* al)
|
||||||
attrs = al;
|
attrs = al;
|
||||||
return_type = 0;
|
return_type = 0;
|
||||||
|
|
||||||
local = new PDict<ID>(ORDERED);
|
|
||||||
inits = new id_list;
|
inits = new id_list;
|
||||||
|
|
||||||
if ( id )
|
if ( id )
|
||||||
|
@ -42,8 +41,8 @@ Scope::Scope(ID* id, attr_list* al)
|
||||||
|
|
||||||
Scope::~Scope()
|
Scope::~Scope()
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < local->Length(); ++i )
|
for ( const auto& entry : local )
|
||||||
Unref(local->NthEntry(i));
|
Unref(entry.second);
|
||||||
|
|
||||||
if ( attrs )
|
if ( attrs )
|
||||||
{
|
{
|
||||||
|
@ -55,7 +54,6 @@ Scope::~Scope()
|
||||||
|
|
||||||
Unref(scope_id);
|
Unref(scope_id);
|
||||||
Unref(return_type);
|
Unref(return_type);
|
||||||
delete local;
|
|
||||||
delete inits;
|
delete inits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +80,7 @@ void Scope::Describe(ODesc* d) const
|
||||||
d->SP();
|
d->SP();
|
||||||
d->Add(return_type != 0);
|
d->Add(return_type != 0);
|
||||||
d->SP();
|
d->SP();
|
||||||
d->Add(local->Length());
|
d->Add(static_cast<uint64_t>(local.size()));
|
||||||
d->SP();
|
d->SP();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +96,9 @@ void Scope::Describe(ODesc* d) const
|
||||||
d->NL();
|
d->NL();
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int i = 0; i < local->Length(); ++i )
|
for ( const auto& entry : local )
|
||||||
{
|
{
|
||||||
ID* id = local->NthEntry(i);
|
ID* id = entry.second;
|
||||||
id->Describe(d);
|
id->Describe(d);
|
||||||
d->NL();
|
d->NL();
|
||||||
}
|
}
|
||||||
|
@ -108,13 +106,9 @@ void Scope::Describe(ODesc* d) const
|
||||||
|
|
||||||
TraversalCode Scope::Traverse(TraversalCallback* cb) const
|
TraversalCode Scope::Traverse(TraversalCallback* cb) const
|
||||||
{
|
{
|
||||||
PDict<ID>* ids = GetIDs();
|
for ( const auto& entry : local )
|
||||||
IterCookie* iter = ids->InitForIteration();
|
|
||||||
|
|
||||||
HashKey* key;
|
|
||||||
ID* id;
|
|
||||||
while ( (id = ids->NextEntry(key, iter)) )
|
|
||||||
{
|
{
|
||||||
|
ID* id = entry.second;
|
||||||
TraversalCode tc = id->Traverse(cb);
|
TraversalCode tc = id->Traverse(cb);
|
||||||
HANDLE_TC_STMT_PRE(tc);
|
HANDLE_TC_STMT_PRE(tc);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +128,7 @@ ID* lookup_ID(const char* name, const char* curr_module, bool no_global,
|
||||||
|
|
||||||
for ( int i = scopes.length() - 1; i >= 0; --i )
|
for ( int i = scopes.length() - 1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
ID* id = scopes[i]->Lookup(fullname.c_str());
|
ID* id = scopes[i]->Lookup(fullname);
|
||||||
if ( id )
|
if ( id )
|
||||||
{
|
{
|
||||||
if ( need_export && ! id->IsExport() && ! in_debug )
|
if ( need_export && ! id->IsExport() && ! in_debug )
|
||||||
|
@ -150,7 +144,7 @@ ID* lookup_ID(const char* name, const char* curr_module, bool no_global,
|
||||||
! same_module_only) )
|
! same_module_only) )
|
||||||
{
|
{
|
||||||
string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name);
|
string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name);
|
||||||
ID* id = global_scope()->Lookup(globalname.c_str());
|
ID* id = global_scope()->Lookup(globalname);
|
||||||
if ( id )
|
if ( id )
|
||||||
{
|
{
|
||||||
Ref(id);
|
Ref(id);
|
||||||
|
|
33
src/Scope.h
33
src/Scope.h
|
@ -4,6 +4,7 @@
|
||||||
#define scope_h
|
#define scope_h
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "Dict.h"
|
#include "Dict.h"
|
||||||
#include "Obj.h"
|
#include "Obj.h"
|
||||||
|
@ -20,25 +21,37 @@ public:
|
||||||
explicit Scope(ID* id, attr_list* al);
|
explicit Scope(ID* id, attr_list* al);
|
||||||
~Scope() override;
|
~Scope() override;
|
||||||
|
|
||||||
ID* Lookup(const char* name) const { return local->Lookup(name); }
|
ID* Lookup(const std::string& name) const
|
||||||
void Insert(const char* name, ID* id) { local->Insert(name, id); }
|
|
||||||
ID* Remove(const char* name)
|
|
||||||
{
|
{
|
||||||
HashKey key(name);
|
const auto& entry = local.find(name);
|
||||||
return (ID*) local->Remove(&key);
|
if ( entry != local.end() )
|
||||||
|
return entry->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
void Insert(const std::string& name, ID* id) { local[name] = id; }
|
||||||
|
ID* Remove(const std::string& name)
|
||||||
|
{
|
||||||
|
const auto& entry = local.find(name);
|
||||||
|
if ( entry != local.end() )
|
||||||
|
{
|
||||||
|
ID* id = entry->second;
|
||||||
|
local.erase(entry);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID* ScopeID() const { return scope_id; }
|
ID* ScopeID() const { return scope_id; }
|
||||||
attr_list* Attrs() const { return attrs; }
|
attr_list* Attrs() const { return attrs; }
|
||||||
BroType* ReturnType() const { return return_type; }
|
BroType* ReturnType() const { return return_type; }
|
||||||
|
|
||||||
int Length() const { return local->Length(); }
|
size_t Length() const { return local.size(); }
|
||||||
PDict<ID>* Vars() const { return local; }
|
std::map<string, ID*>& Vars() { return local; }
|
||||||
|
|
||||||
ID* GenerateTemporary(const char* name);
|
ID* GenerateTemporary(const char* name);
|
||||||
|
|
||||||
PDict<ID>* GetIDs() const { return local; }
|
|
||||||
|
|
||||||
// Returns the list of variables needing initialization, and
|
// Returns the list of variables needing initialization, and
|
||||||
// removes it from this Scope.
|
// removes it from this Scope.
|
||||||
id_list* GetInits();
|
id_list* GetInits();
|
||||||
|
@ -54,7 +67,7 @@ protected:
|
||||||
ID* scope_id;
|
ID* scope_id;
|
||||||
attr_list* attrs;
|
attr_list* attrs;
|
||||||
BroType* return_type;
|
BroType* return_type;
|
||||||
PDict<ID>* local;
|
std::map<string, ID*> local;
|
||||||
id_list* inits;
|
id_list* inits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -239,7 +239,7 @@ void ProfileLogger::Log()
|
||||||
|
|
||||||
// Script-level state.
|
// Script-level state.
|
||||||
unsigned int size, mem = 0;
|
unsigned int size, mem = 0;
|
||||||
PDict<ID>* globals = global_scope()->Vars();
|
const auto& globals = global_scope()->Vars();
|
||||||
|
|
||||||
if ( expensive )
|
if ( expensive )
|
||||||
{
|
{
|
||||||
|
@ -249,10 +249,10 @@ void ProfileLogger::Log()
|
||||||
file->Write(fmt("%.06f Global_sizes > 100k: %dK\n",
|
file->Write(fmt("%.06f Global_sizes > 100k: %dK\n",
|
||||||
network_time, mem / 1024));
|
network_time, mem / 1024));
|
||||||
|
|
||||||
ID* id;
|
for ( const auto& global : globals )
|
||||||
IterCookie* c = globals->InitForIteration();
|
{
|
||||||
|
ID* id = global.second;
|
||||||
|
|
||||||
while ( (id = globals->NextEntry(c)) )
|
|
||||||
// We don't show/count internal globals as they are always
|
// We don't show/count internal globals as they are always
|
||||||
// contained in some other global user-visible container.
|
// contained in some other global user-visible container.
|
||||||
if ( id->HasVal() )
|
if ( id->HasVal() )
|
||||||
|
@ -298,6 +298,7 @@ void ProfileLogger::Log()
|
||||||
file->Write("\n");
|
file->Write("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
file->Write(fmt("%.06f Global_sizes total: %dK\n",
|
file->Write(fmt("%.06f Global_sizes total: %dK\n",
|
||||||
network_time, mem / 1024));
|
network_time, mem / 1024));
|
||||||
|
|
|
@ -50,11 +50,11 @@ bool Stmt::SetLocationInfo(const Location* start, const Location* end)
|
||||||
|
|
||||||
// Update the Filemap of line number -> statement mapping for
|
// Update the Filemap of line number -> statement mapping for
|
||||||
// breakpoints (Debug.h).
|
// breakpoints (Debug.h).
|
||||||
Filemap* map_ptr = (Filemap*) g_dbgfilemaps.Lookup(location->filename);
|
auto map_iter = g_dbgfilemaps.find(location->filename);
|
||||||
if ( ! map_ptr )
|
if ( map_iter == g_dbgfilemaps.end() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Filemap& map = *map_ptr;
|
Filemap& map = *(map_iter->second);
|
||||||
|
|
||||||
StmtLocMapping* new_mapping = new StmtLocMapping(GetLocationInfo(), this);
|
StmtLocMapping* new_mapping = new StmtLocMapping(GetLocationInfo(), this);
|
||||||
|
|
||||||
|
|
|
@ -1799,7 +1799,7 @@ BroType* merge_types(const BroType* t1, const BroType* t2)
|
||||||
// Doing a lookup here as a roundabout way of ref-ing t1, without
|
// Doing a lookup here as a roundabout way of ref-ing t1, without
|
||||||
// changing the function params which has t1 as const and also
|
// changing the function params which has t1 as const and also
|
||||||
// (potentially) avoiding a pitfall mentioned earlier about clones.
|
// (potentially) avoiding a pitfall mentioned earlier about clones.
|
||||||
auto id = global_scope()->Lookup(t1->GetName().data());
|
auto id = global_scope()->Lookup(t1->GetName());
|
||||||
|
|
||||||
if ( id && id->AsType() && id->AsType()->Tag() == TYPE_ENUM )
|
if ( id && id->AsType() && id->AsType()->Tag() == TYPE_ENUM )
|
||||||
// It should make most sense to return the real type here rather
|
// It should make most sense to return the real type here rather
|
||||||
|
|
|
@ -264,7 +264,7 @@ public:
|
||||||
virtual unsigned MemoryAllocation() const;
|
virtual unsigned MemoryAllocation() const;
|
||||||
|
|
||||||
void SetName(const string& arg_name) { name = arg_name; }
|
void SetName(const string& arg_name) { name = arg_name; }
|
||||||
string GetName() const { return name; }
|
const string& GetName() const { return name; }
|
||||||
|
|
||||||
typedef std::map<std::string, std::set<BroType*> > TypeAliasMap;
|
typedef std::map<std::string, std::set<BroType*> > TypeAliasMap;
|
||||||
|
|
||||||
|
|
|
@ -429,7 +429,7 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
||||||
if ( e->Id()->IsGlobal() )
|
if ( e->Id()->IsGlobal() )
|
||||||
return TC_CONTINUE;
|
return TC_CONTINUE;
|
||||||
|
|
||||||
if ( scope->GetIDs()->Lookup(e->Id()->Name()) )
|
if ( scope->Lookup(e->Id()->Name()) )
|
||||||
return TC_CONTINUE;
|
return TC_CONTINUE;
|
||||||
|
|
||||||
outer_id_references.push_back(e);
|
outer_id_references.push_back(e);
|
||||||
|
|
|
@ -98,19 +98,15 @@ int RPC_CallInfo::CompareRexmit(const u_char* buf, int n) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void rpc_callinfo_delete_func(void* v)
|
|
||||||
{
|
|
||||||
delete (RPC_CallInfo*) v;
|
|
||||||
}
|
|
||||||
|
|
||||||
RPC_Interpreter::RPC_Interpreter(analyzer::Analyzer* arg_analyzer)
|
RPC_Interpreter::RPC_Interpreter(analyzer::Analyzer* arg_analyzer)
|
||||||
{
|
{
|
||||||
analyzer = arg_analyzer;
|
analyzer = arg_analyzer;
|
||||||
calls.SetDeleteFunc(rpc_callinfo_delete_func);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RPC_Interpreter::~RPC_Interpreter()
|
RPC_Interpreter::~RPC_Interpreter()
|
||||||
{
|
{
|
||||||
|
for ( const auto& call : calls )
|
||||||
|
delete call.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
||||||
|
@ -123,8 +119,10 @@ int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
||||||
if ( ! buf )
|
if ( ! buf )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
HashKey h(&xid, 1);
|
RPC_CallInfo* call = nullptr;
|
||||||
RPC_CallInfo* call = calls.Lookup(&h);
|
auto iter = calls.find(xid);
|
||||||
|
if ( iter != calls.end() )
|
||||||
|
call = iter->second;
|
||||||
|
|
||||||
if ( msg_type == RPC_CALL )
|
if ( msg_type == RPC_CALL )
|
||||||
{
|
{
|
||||||
|
@ -164,7 +162,7 @@ int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
calls.Insert(&h, call);
|
calls[xid] = call;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We now have a valid RPC_CallInfo (either the previous one
|
// We now have a valid RPC_CallInfo (either the previous one
|
||||||
|
@ -274,7 +272,8 @@ int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
||||||
|
|
||||||
Event_RPC_Dialogue(call, status, n);
|
Event_RPC_Dialogue(call, status, n);
|
||||||
|
|
||||||
delete calls.RemoveEntry(&h);
|
calls.erase(xid);
|
||||||
|
delete call;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -308,11 +307,9 @@ int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen,
|
||||||
|
|
||||||
void RPC_Interpreter::Timeout()
|
void RPC_Interpreter::Timeout()
|
||||||
{
|
{
|
||||||
IterCookie* cookie = calls.InitForIteration();
|
for ( const auto& entry : calls )
|
||||||
RPC_CallInfo* c;
|
|
||||||
|
|
||||||
while ( (c = calls.NextEntry(cookie)) )
|
|
||||||
{
|
{
|
||||||
|
RPC_CallInfo* c = entry.second;
|
||||||
Event_RPC_Dialogue(c, BifEnum::RPC_TIMEOUT, 0);
|
Event_RPC_Dialogue(c, BifEnum::RPC_TIMEOUT, 0);
|
||||||
|
|
||||||
if ( c->IsValidCall() )
|
if ( c->IsValidCall() )
|
||||||
|
|
|
@ -123,7 +123,7 @@ protected:
|
||||||
|
|
||||||
void Weird(const char* name, const char* addl = "");
|
void Weird(const char* name, const char* addl = "");
|
||||||
|
|
||||||
PDict<RPC_CallInfo> calls;
|
std::map<uint32, RPC_CallInfo*> calls;
|
||||||
analyzer::Analyzer* analyzer;
|
analyzer::Analyzer* analyzer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ SteppingStoneEndpoint::SteppingStoneEndpoint(tcp::TCP_Endpoint* e, SteppingStone
|
||||||
stp_last_time = stp_resume_time = 0.0;
|
stp_last_time = stp_resume_time = 0.0;
|
||||||
stp_manager = m;
|
stp_manager = m;
|
||||||
stp_id = stp_manager->NextID();
|
stp_id = stp_manager->NextID();
|
||||||
stp_key = new HashKey(bro_int_t(stp_id));
|
|
||||||
|
|
||||||
CreateEndpEvent(e->IsOrig());
|
CreateEndpEvent(e->IsOrig());
|
||||||
|
|
||||||
|
@ -32,7 +31,6 @@ SteppingStoneEndpoint::SteppingStoneEndpoint(tcp::TCP_Endpoint* e, SteppingStone
|
||||||
|
|
||||||
SteppingStoneEndpoint::~SteppingStoneEndpoint()
|
SteppingStoneEndpoint::~SteppingStoneEndpoint()
|
||||||
{
|
{
|
||||||
delete stp_key;
|
|
||||||
Unref(endp->TCP()->Conn());
|
Unref(endp->TCP()->Conn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,20 +40,19 @@ void SteppingStoneEndpoint::Done()
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SteppingStoneEndpoint* ep;
|
SteppingStoneEndpoint* ep;
|
||||||
IterCookie* cookie;
|
|
||||||
|
|
||||||
cookie = stp_inbound_endps.InitForIteration();
|
for ( const auto& entry : stp_inbound_endps )
|
||||||
while ( (ep = stp_inbound_endps.NextEntry(cookie)) )
|
|
||||||
{
|
{
|
||||||
ep->stp_outbound_endps.Remove(stp_key);
|
ep = entry.second;
|
||||||
|
ep->stp_outbound_endps.erase(stp_id);
|
||||||
Event(stp_remove_pair, ep->stp_id, stp_id);
|
Event(stp_remove_pair, ep->stp_id, stp_id);
|
||||||
Unref(ep);
|
Unref(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
cookie = stp_outbound_endps.InitForIteration();
|
for ( const auto& entry : stp_outbound_endps )
|
||||||
while ( (ep = stp_outbound_endps.NextEntry(cookie)) )
|
|
||||||
{
|
{
|
||||||
ep->stp_inbound_endps.Remove(stp_key);
|
ep = entry.second;
|
||||||
|
ep->stp_inbound_endps.erase(stp_id);
|
||||||
Event(stp_remove_pair, stp_id, ep->stp_id);
|
Event(stp_remove_pair, stp_id, ep->stp_id);
|
||||||
Unref(ep);
|
Unref(ep);
|
||||||
}
|
}
|
||||||
|
@ -115,8 +112,8 @@ int SteppingStoneEndpoint::DataSent(double t, uint64 seq, int len, int caplen,
|
||||||
Ref(ep);
|
Ref(ep);
|
||||||
Ref(this);
|
Ref(this);
|
||||||
|
|
||||||
stp_inbound_endps.Insert(ep->stp_key, ep);
|
stp_inbound_endps[ep->stp_id] = ep;
|
||||||
ep->stp_outbound_endps.Insert(stp_key, this);
|
ep->stp_outbound_endps[stp_id] = this;
|
||||||
|
|
||||||
Event(stp_correlate_pair, ep->stp_id, stp_id);
|
Event(stp_correlate_pair, ep->stp_id, stp_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,8 @@ protected:
|
||||||
// removing correlated endpoint pairs in Bro, since there is
|
// removing correlated endpoint pairs in Bro, since there is
|
||||||
// no LOOP in Bro language.
|
// no LOOP in Bro language.
|
||||||
int stp_id;
|
int stp_id;
|
||||||
HashKey* stp_key;
|
std::map<int, SteppingStoneEndpoint*> stp_inbound_endps;
|
||||||
PDict<SteppingStoneEndpoint> stp_inbound_endps;
|
std::map<int, SteppingStoneEndpoint*> stp_outbound_endps;
|
||||||
PDict<SteppingStoneEndpoint> stp_outbound_endps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SteppingStone_Analyzer : public tcp::TCP_ApplicationAnalyzer {
|
class SteppingStone_Analyzer : public tcp::TCP_ApplicationAnalyzer {
|
||||||
|
|
|
@ -351,7 +351,7 @@ struct val_converter {
|
||||||
if ( ! name )
|
if ( ! name )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto id = global_scope()->Lookup(name->c_str());
|
auto id = global_scope()->Lookup(*name);
|
||||||
if ( ! id )
|
if ( ! id )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@ struct type_checker {
|
||||||
if ( ! name )
|
if ( ! name )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto id = global_scope()->Lookup(name->c_str());
|
auto id = global_scope()->Lookup(*name);
|
||||||
if ( ! id )
|
if ( ! id )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -407,7 +407,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id)
|
||||||
if ( peer_count == 0 )
|
if ( peer_count == 0 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ID* i = global_scope()->Lookup(id.c_str());
|
ID* i = global_scope()->Lookup(id);
|
||||||
|
|
||||||
if ( ! i )
|
if ( ! i )
|
||||||
return false;
|
return false;
|
||||||
|
@ -998,7 +998,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev)
|
||||||
DBG_LOG(DBG_BROKER, "Process event: %s %s",
|
DBG_LOG(DBG_BROKER, "Process event: %s %s",
|
||||||
name.data(), RenderMessage(args).data());
|
name.data(), RenderMessage(args).data());
|
||||||
++statistics.num_events_incoming;
|
++statistics.num_events_incoming;
|
||||||
auto handler = event_registry->Lookup(name.data());
|
auto handler = event_registry->Lookup(name);
|
||||||
|
|
||||||
if ( ! handler )
|
if ( ! handler )
|
||||||
return;
|
return;
|
||||||
|
@ -1240,7 +1240,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu)
|
||||||
++statistics.num_ids_incoming;
|
++statistics.num_ids_incoming;
|
||||||
auto id_name = std::move(iu.id_name());
|
auto id_name = std::move(iu.id_name());
|
||||||
auto id_value = std::move(iu.id_value());
|
auto id_value = std::move(iu.id_value());
|
||||||
auto id = global_scope()->Lookup(id_name.c_str());
|
auto id = global_scope()->Lookup(id_name);
|
||||||
|
|
||||||
if ( ! id )
|
if ( ! id )
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ string Manager::salt;
|
||||||
Manager::Manager()
|
Manager::Manager()
|
||||||
: plugin::ComponentManager<file_analysis::Tag,
|
: plugin::ComponentManager<file_analysis::Tag,
|
||||||
file_analysis::Component>("Files", "Tag"),
|
file_analysis::Component>("Files", "Tag"),
|
||||||
id_map(), ignored(), current_file_id(), magic_state()
|
current_file_id(), magic_state(), cumulative_files(0), max_files(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,21 +33,10 @@ Manager::~Manager()
|
||||||
for ( MIMEMap::iterator i = mime_types.begin(); i != mime_types.end(); i++ )
|
for ( MIMEMap::iterator i = mime_types.begin(); i != mime_types.end(); i++ )
|
||||||
delete i->second;
|
delete i->second;
|
||||||
|
|
||||||
// Have to assume that too much of Bro has been shutdown by this point
|
// Have to assume that too much of Zeek has been shutdown by this point
|
||||||
// to do anything more than reclaim memory.
|
// to do anything more than reclaim memory.
|
||||||
|
for ( const auto& entry : id_map )
|
||||||
File* f;
|
delete entry.second;
|
||||||
bool* b;
|
|
||||||
|
|
||||||
IterCookie* it = id_map.InitForIteration();
|
|
||||||
|
|
||||||
while ( (f = id_map.NextEntry(it)) )
|
|
||||||
delete f;
|
|
||||||
|
|
||||||
it = ignored.InitForIteration();
|
|
||||||
|
|
||||||
while( (b = ignored.NextEntry(it)) )
|
|
||||||
delete b;
|
|
||||||
|
|
||||||
delete magic_state;
|
delete magic_state;
|
||||||
}
|
}
|
||||||
|
@ -69,19 +58,13 @@ void Manager::InitMagic()
|
||||||
void Manager::Terminate()
|
void Manager::Terminate()
|
||||||
{
|
{
|
||||||
vector<string> keys;
|
vector<string> keys;
|
||||||
|
keys.reserve(id_map.size());
|
||||||
|
|
||||||
IterCookie* it = id_map.InitForIteration();
|
for ( const auto& entry : id_map )
|
||||||
HashKey* key;
|
keys.push_back(entry.first);
|
||||||
|
|
||||||
while ( id_map.NextEntry(key, it) )
|
for ( const string& key : keys )
|
||||||
{
|
Timeout(key, true);
|
||||||
keys.push_back(string(static_cast<const char*>(key->Key()),
|
|
||||||
key->Size()));
|
|
||||||
delete key;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( size_t i = 0; i < keys.size(); ++i )
|
|
||||||
Timeout(keys[i], true);
|
|
||||||
|
|
||||||
mgr.Drain();
|
mgr.Drain();
|
||||||
}
|
}
|
||||||
|
@ -329,7 +312,7 @@ File* Manager::GetFile(const string& file_id, Connection* conn,
|
||||||
if ( IsIgnored(file_id) )
|
if ( IsIgnored(file_id) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
File* rval = id_map.Lookup(file_id.c_str());
|
File* rval = LookupFile(file_id);
|
||||||
|
|
||||||
if ( ! rval )
|
if ( ! rval )
|
||||||
{
|
{
|
||||||
|
@ -337,7 +320,12 @@ File* Manager::GetFile(const string& file_id, Connection* conn,
|
||||||
source_name ? source_name
|
source_name ? source_name
|
||||||
: analyzer_mgr->GetComponentName(tag),
|
: analyzer_mgr->GetComponentName(tag),
|
||||||
conn, tag, is_orig);
|
conn, tag, is_orig);
|
||||||
id_map.Insert(file_id.c_str(), rval);
|
id_map[file_id] = rval;
|
||||||
|
|
||||||
|
++cumulative_files;
|
||||||
|
if ( id_map.size() > max_files )
|
||||||
|
max_files = id_map.size();
|
||||||
|
|
||||||
rval->ScheduleInactivityTimer();
|
rval->ScheduleInactivityTimer();
|
||||||
|
|
||||||
// Generate file_new after inserting it into manager's mapping
|
// Generate file_new after inserting it into manager's mapping
|
||||||
|
@ -362,7 +350,11 @@ File* Manager::GetFile(const string& file_id, Connection* conn,
|
||||||
|
|
||||||
File* Manager::LookupFile(const string& file_id) const
|
File* Manager::LookupFile(const string& file_id) const
|
||||||
{
|
{
|
||||||
return id_map.Lookup(file_id.c_str());
|
const auto& entry = id_map.find(file_id);
|
||||||
|
if ( entry == id_map.end() )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return entry->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Timeout(const string& file_id, bool is_terminating)
|
void Manager::Timeout(const string& file_id, bool is_terminating)
|
||||||
|
@ -393,22 +385,21 @@ void Manager::Timeout(const string& file_id, bool is_terminating)
|
||||||
|
|
||||||
bool Manager::IgnoreFile(const string& file_id)
|
bool Manager::IgnoreFile(const string& file_id)
|
||||||
{
|
{
|
||||||
if ( ! id_map.Lookup(file_id.c_str()) )
|
if ( ! LookupFile(file_id) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DBG_LOG(DBG_FILE_ANALYSIS, "Ignore FileID %s", file_id.c_str());
|
DBG_LOG(DBG_FILE_ANALYSIS, "Ignore FileID %s", file_id.c_str());
|
||||||
|
|
||||||
delete ignored.Insert(file_id.c_str(), new bool);
|
ignored.insert(file_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::RemoveFile(const string& file_id)
|
bool Manager::RemoveFile(const string& file_id)
|
||||||
{
|
{
|
||||||
HashKey key(file_id.c_str());
|
|
||||||
// Can't remove from the dictionary/map right away as invoking EndOfFile
|
// Can't remove from the dictionary/map right away as invoking EndOfFile
|
||||||
// may cause some events to be executed which actually depend on the file
|
// may cause some events to be executed which actually depend on the file
|
||||||
// still being in the dictionary/map.
|
// still being in the dictionary/map.
|
||||||
File* f = static_cast<File*>(id_map.Lookup(&key));
|
File* f = LookupFile(file_id);
|
||||||
|
|
||||||
if ( ! f )
|
if ( ! f )
|
||||||
return false;
|
return false;
|
||||||
|
@ -417,14 +408,15 @@ bool Manager::RemoveFile(const string& file_id)
|
||||||
|
|
||||||
f->EndOfFile();
|
f->EndOfFile();
|
||||||
delete f;
|
delete f;
|
||||||
id_map.Remove(&key);
|
|
||||||
delete static_cast<bool*>(ignored.Remove(&key));
|
id_map.erase(file_id);
|
||||||
|
ignored.erase(file_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::IsIgnored(const string& file_id)
|
bool Manager::IsIgnored(const string& file_id)
|
||||||
{
|
{
|
||||||
return ignored.Lookup(file_id.c_str()) != 0;
|
return ignored.find(file_id) != ignored.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
string Manager::GetFileID(analyzer::Tag tag, Connection* c, bool is_orig)
|
string Manager::GetFileID(analyzer::Tag tag, Connection* c, bool is_orig)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "Dict.h"
|
#include "Dict.h"
|
||||||
#include "Net.h"
|
#include "Net.h"
|
||||||
|
@ -325,20 +326,17 @@ public:
|
||||||
std::string DetectMIME(const u_char* data, uint64 len) const;
|
std::string DetectMIME(const u_char* data, uint64 len) const;
|
||||||
|
|
||||||
uint64 CurrentFiles()
|
uint64 CurrentFiles()
|
||||||
{ return id_map.Length(); }
|
{ return id_map.size(); }
|
||||||
|
|
||||||
uint64 MaxFiles()
|
uint64 MaxFiles()
|
||||||
{ return id_map.MaxLength(); }
|
{ return max_files; }
|
||||||
|
|
||||||
uint64 CumulativeFiles()
|
uint64 CumulativeFiles()
|
||||||
{ return id_map.NumCumulativeInserts(); }
|
{ return cumulative_files; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class FileTimer;
|
friend class FileTimer;
|
||||||
|
|
||||||
typedef PDict<bool> IDSet;
|
|
||||||
typedef PDict<File> IDMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new file to be analyzed or retrieve an existing one.
|
* Create a new file to be analyzed or retrieve an existing one.
|
||||||
* @param file_id the file identifier/hash.
|
* @param file_id the file identifier/hash.
|
||||||
|
@ -407,8 +405,8 @@ private:
|
||||||
|
|
||||||
TagSet* LookupMIMEType(const string& mtype, bool add_if_not_found);
|
TagSet* LookupMIMEType(const string& mtype, bool add_if_not_found);
|
||||||
|
|
||||||
PDict<File> id_map; /**< Map file ID to file_analysis::File records. */
|
std::map<string, File*> id_map; /**< Map file ID to file_analysis::File records. */
|
||||||
PDict<bool> ignored; /**< Ignored files. Will be finally removed on EOF. */
|
std::unordered_set<string> ignored; /**< Ignored files. Will be finally removed on EOF. */
|
||||||
string current_file_id; /**< Hash of what get_file_handle event sets. */
|
string current_file_id; /**< Hash of what get_file_handle event sets. */
|
||||||
RuleFileMagicState* magic_state; /**< File magic signature match state. */
|
RuleFileMagicState* magic_state; /**< File magic signature match state. */
|
||||||
MIMEMap mime_types;/**< Mapping of MIME types to analyzers. */
|
MIMEMap mime_types;/**< Mapping of MIME types to analyzers. */
|
||||||
|
@ -416,6 +414,9 @@ private:
|
||||||
static TableVal* disabled; /**< Table of disabled analyzers. */
|
static TableVal* disabled; /**< Table of disabled analyzers. */
|
||||||
static TableType* tag_set_type; /**< Type for set[tag]. */
|
static TableType* tag_set_type; /**< Type for set[tag]. */
|
||||||
static string salt; /**< A salt added to file handles before hashing. */
|
static string salt; /**< A salt added to file handles before hashing. */
|
||||||
|
|
||||||
|
size_t cumulative_files;
|
||||||
|
size_t max_files;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -153,31 +153,31 @@ Manager::EventStream::EventStream()
|
||||||
|
|
||||||
Manager::EventStream::~EventStream()
|
Manager::EventStream::~EventStream()
|
||||||
{
|
{
|
||||||
if ( fields )
|
if ( fields )
|
||||||
Unref(fields);
|
Unref(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::TableStream::~TableStream()
|
Manager::TableStream::~TableStream()
|
||||||
{
|
{
|
||||||
if ( tab )
|
if ( tab )
|
||||||
Unref(tab);
|
Unref(tab);
|
||||||
|
|
||||||
if ( itype )
|
if ( itype )
|
||||||
Unref(itype);
|
Unref(itype);
|
||||||
|
|
||||||
if ( rtype ) // can be 0 for sets
|
if ( rtype ) // can be 0 for sets
|
||||||
Unref(rtype);
|
Unref(rtype);
|
||||||
|
|
||||||
if ( currDict != 0 )
|
if ( currDict != 0 )
|
||||||
{
|
{
|
||||||
currDict->Clear();
|
currDict->Clear();
|
||||||
delete currDict;
|
delete currDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( lastDict != 0 )
|
if ( lastDict != 0 )
|
||||||
{
|
{
|
||||||
lastDict->Clear();;
|
lastDict->Clear();;
|
||||||
delete lastDict;
|
delete lastDict;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1852,7 +1852,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandler* handler = event_registry->Lookup(name.c_str());
|
EventHandler* handler = event_registry->Lookup(name);
|
||||||
if ( handler == 0 )
|
if ( handler == 0 )
|
||||||
{
|
{
|
||||||
Warning(i, "Event %s not found", name.c_str());
|
Warning(i, "Event %s not found", name.c_str());
|
||||||
|
|
|
@ -28,11 +28,11 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
|
||||||
fail_on_file_problem = false;
|
fail_on_file_problem = false;
|
||||||
|
|
||||||
// find all option names and their types.
|
// find all option names and their types.
|
||||||
auto globals = global_scope()->Vars();
|
const auto& globals = global_scope()->Vars();
|
||||||
auto c = globals->InitForIteration();
|
|
||||||
|
|
||||||
while ( auto id = globals->NextEntry(c) )
|
for ( const auto& entry : globals )
|
||||||
{
|
{
|
||||||
|
ID* id = entry.second;
|
||||||
if ( ! id->IsOption() )
|
if ( ! id->IsOption() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
10
src/main.cc
10
src/main.cc
|
@ -982,17 +982,15 @@ int main(int argc, char** argv)
|
||||||
if ( zeek_init ) //### this should be a function
|
if ( zeek_init ) //### this should be a function
|
||||||
mgr.QueueEventFast(zeek_init, val_list{});
|
mgr.QueueEventFast(zeek_init, val_list{});
|
||||||
|
|
||||||
EventRegistry::string_list* dead_handlers =
|
EventRegistry::string_list dead_handlers =
|
||||||
event_registry->UnusedHandlers();
|
event_registry->UnusedHandlers();
|
||||||
|
|
||||||
if ( dead_handlers->length() > 0 && check_for_unused_event_handlers )
|
if ( ! dead_handlers.empty() && check_for_unused_event_handlers )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < dead_handlers->length(); ++i )
|
for ( const string& handler : dead_handlers )
|
||||||
reporter->Warning("event handler never invoked: %s", (*dead_handlers)[i]);
|
reporter->Warning("event handler never invoked: %s", handler.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
delete dead_handlers;
|
|
||||||
|
|
||||||
if ( stmts )
|
if ( stmts )
|
||||||
{
|
{
|
||||||
stmt_flow_type flow;
|
stmt_flow_type flow;
|
||||||
|
|
|
@ -85,14 +85,14 @@ CCL_EXPR ("[:"[[:alpha:]]+":]")
|
||||||
char* nmstr = copy_string(yytext+1);
|
char* nmstr = copy_string(yytext+1);
|
||||||
nmstr[yyleng - 2] = '\0'; // chop trailing brace
|
nmstr[yyleng - 2] = '\0'; // chop trailing brace
|
||||||
|
|
||||||
const char* namedef = rem->LookupDef(nmstr);
|
std::string namedef = rem->LookupDef(nmstr);
|
||||||
delete nmstr;
|
delete nmstr;
|
||||||
|
|
||||||
if ( ! namedef )
|
if ( namedef.empty() )
|
||||||
synerr("undefined definition");
|
synerr("undefined definition");
|
||||||
else
|
else
|
||||||
{ // push back name surrounded by ()'s
|
{ // push back name surrounded by ()'s
|
||||||
int len = strlen(namedef);
|
int len = namedef.size();
|
||||||
|
|
||||||
if ( namedef[0] == '^' ||
|
if ( namedef[0] == '^' ||
|
||||||
(len > 0 && namedef[len - 1] == '$') )
|
(len > 0 && namedef[len - 1] == '$') )
|
||||||
|
|
|
@ -671,7 +671,7 @@ static int load_files(const char* orig_file)
|
||||||
// Add the filename to the file mapping table (Debug.h).
|
// Add the filename to the file mapping table (Debug.h).
|
||||||
Filemap* map = new Filemap;
|
Filemap* map = new Filemap;
|
||||||
HashKey* key = new HashKey(file_path.c_str());
|
HashKey* key = new HashKey(file_path.c_str());
|
||||||
g_dbgfilemaps.Insert(key, map);
|
g_dbgfilemaps.emplace(file_path, map);
|
||||||
LoadPolicyFileText(file_path.c_str());
|
LoadPolicyFileText(file_path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/zeek.bif
16
src/zeek.bif
|
@ -1895,11 +1895,11 @@ function reading_traces%(%): bool
|
||||||
function global_sizes%(%): var_sizes
|
function global_sizes%(%): var_sizes
|
||||||
%{
|
%{
|
||||||
TableVal* sizes = new TableVal(var_sizes);
|
TableVal* sizes = new TableVal(var_sizes);
|
||||||
PDict<ID>* globals = global_scope()->Vars();
|
const auto& globals = global_scope()->Vars();
|
||||||
IterCookie* c = globals->InitForIteration();
|
|
||||||
|
|
||||||
ID* id;
|
for ( const auto& global : globals )
|
||||||
while ( (id = globals->NextEntry(c)) )
|
{
|
||||||
|
ID* id = global.second;
|
||||||
if ( id->HasVal() )
|
if ( id->HasVal() )
|
||||||
{
|
{
|
||||||
Val* id_name = new StringVal(id->Name());
|
Val* id_name = new StringVal(id->Name());
|
||||||
|
@ -1907,6 +1907,7 @@ function global_sizes%(%): var_sizes
|
||||||
sizes->Assign(id_name, id_size);
|
sizes->Assign(id_name, id_size);
|
||||||
Unref(id_name);
|
Unref(id_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sizes;
|
return sizes;
|
||||||
%}
|
%}
|
||||||
|
@ -1922,12 +1923,11 @@ function global_sizes%(%): var_sizes
|
||||||
function global_ids%(%): id_table
|
function global_ids%(%): id_table
|
||||||
%{
|
%{
|
||||||
TableVal* ids = new TableVal(id_table);
|
TableVal* ids = new TableVal(id_table);
|
||||||
PDict<ID>* globals = global_scope()->Vars();
|
const auto& globals = global_scope()->Vars();
|
||||||
IterCookie* c = globals->InitForIteration();
|
|
||||||
|
|
||||||
ID* id;
|
for ( const auto& global : globals )
|
||||||
while ( (id = globals->NextEntry(c)) )
|
|
||||||
{
|
{
|
||||||
|
ID* id = global.second;
|
||||||
RecordVal* rec = new RecordVal(script_id);
|
RecordVal* rec = new RecordVal(script_id);
|
||||||
rec->Assign(0, new StringVal(type_name(id->Type()->Tag())));
|
rec->Assign(0, new StringVal(type_name(id->Type()->Tag())));
|
||||||
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
rec->Assign(1, val_mgr->GetBool(id->IsExport()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue