mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Making plugin names case-insensitive for some internal comparisions.
Makes the plugin system a bit more tolerant against spelling inconsistencies that would be hard to catch otherwise.
This commit is contained in:
parent
ab3cdf494a
commit
0f96d06252
3 changed files with 22 additions and 10 deletions
|
@ -79,18 +79,19 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
|
||||||
std::string name;
|
std::string name;
|
||||||
std::getline(in, name);
|
std::getline(in, name);
|
||||||
strstrip(name);
|
strstrip(name);
|
||||||
|
string lower_name = strtolower(name);
|
||||||
|
|
||||||
if ( name.empty() )
|
if ( name.empty() )
|
||||||
reporter->FatalError("empty plugin magic file %s", magic.c_str());
|
reporter->FatalError("empty plugin magic file %s", magic.c_str());
|
||||||
|
|
||||||
if ( dynamic_plugins.find(name) != dynamic_plugins.end() )
|
if ( dynamic_plugins.find(lower_name) != dynamic_plugins.end() )
|
||||||
{
|
{
|
||||||
DBG_LOG(DBG_PLUGINS, "Found already known plugin %s in %s, ignoring", name.c_str(), dir.c_str());
|
DBG_LOG(DBG_PLUGINS, "Found already known plugin %s in %s, ignoring", name.c_str(), dir.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record it, so that we can later activate it.
|
// Record it, so that we can later activate it.
|
||||||
dynamic_plugins.insert(std::make_pair(name, dir));
|
dynamic_plugins.insert(std::make_pair(lower_name, dir));
|
||||||
|
|
||||||
DBG_LOG(DBG_PLUGINS, "Found plugin %s in %s", name.c_str(), dir.c_str());
|
DBG_LOG(DBG_PLUGINS, "Found plugin %s in %s", name.c_str(), dir.c_str());
|
||||||
return;
|
return;
|
||||||
|
@ -135,7 +136,7 @@ void Manager::SearchDynamicPlugins(const std::string& dir)
|
||||||
|
|
||||||
bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found)
|
bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found)
|
||||||
{
|
{
|
||||||
dynamic_plugin_map::iterator m = dynamic_plugins.find(name);
|
dynamic_plugin_map::iterator m = dynamic_plugins.find(strtolower(name));
|
||||||
|
|
||||||
if ( m == dynamic_plugins.end() )
|
if ( m == dynamic_plugins.end() )
|
||||||
{
|
{
|
||||||
|
@ -230,7 +231,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
|
||||||
|
|
||||||
// Make sure the name the plugin reports is consistent with
|
// Make sure the name the plugin reports is consistent with
|
||||||
// what we expect from its magic file.
|
// what we expect from its magic file.
|
||||||
if ( string(current_plugin->Name()) != name )
|
if ( strtolower(current_plugin->Name()) != strtolower(name) )
|
||||||
reporter->FatalError("inconsistent plugin name: %s vs %s",
|
reporter->FatalError("inconsistent plugin name: %s vs %s",
|
||||||
current_plugin->Name().c_str(), name.c_str());
|
current_plugin->Name().c_str(), name.c_str());
|
||||||
|
|
||||||
|
@ -297,7 +298,7 @@ void Manager::UpdateInputFiles()
|
||||||
|
|
||||||
static bool plugin_cmp(const Plugin* a, const Plugin* b)
|
static bool plugin_cmp(const Plugin* a, const Plugin* b)
|
||||||
{
|
{
|
||||||
return a->Name() < b->Name();
|
return strtolower(a->Name()) < strtolower(b->Name());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::RegisterPlugin(Plugin *plugin)
|
void Manager::RegisterPlugin(Plugin *plugin)
|
||||||
|
@ -318,10 +319,11 @@ void Manager::RegisterBifFile(const char* plugin, bif_init_func c)
|
||||||
{
|
{
|
||||||
bif_init_func_map* bifs = BifFilesInternal();
|
bif_init_func_map* bifs = BifFilesInternal();
|
||||||
|
|
||||||
bif_init_func_map::iterator i = bifs->find(plugin);
|
std::string lower_plugin = strtolower(plugin);
|
||||||
|
bif_init_func_map::iterator i = bifs->find(lower_plugin);
|
||||||
|
|
||||||
if ( i == bifs->end() )
|
if ( i == bifs->end() )
|
||||||
i = bifs->insert(std::make_pair(std::string(plugin), new bif_init_func_list())).first;
|
i = bifs->insert(std::make_pair(lower_plugin, new bif_init_func_list())).first;
|
||||||
|
|
||||||
i->second->push_back(c);
|
i->second->push_back(c);
|
||||||
}
|
}
|
||||||
|
@ -348,7 +350,7 @@ void Manager::InitBifs()
|
||||||
for ( plugin_list::iterator i = Manager::ActivePluginsInternal()->begin();
|
for ( plugin_list::iterator i = Manager::ActivePluginsInternal()->begin();
|
||||||
i != Manager::ActivePluginsInternal()->end(); i++ )
|
i != Manager::ActivePluginsInternal()->end(); i++ )
|
||||||
{
|
{
|
||||||
bif_init_func_map::const_iterator b = bifs->find((*i)->Name());
|
bif_init_func_map::const_iterator b = bifs->find(strtolower((*i)->Name()));
|
||||||
|
|
||||||
if ( b != bifs->end() )
|
if ( b != bifs->end() )
|
||||||
{
|
{
|
||||||
|
@ -397,7 +399,7 @@ Manager::inactive_plugin_list Manager::InactivePlugins() const
|
||||||
|
|
||||||
for ( plugin_list::const_iterator j = all->begin(); j != all->end(); j++ )
|
for ( plugin_list::const_iterator j = all->begin(); j != all->end(); j++ )
|
||||||
{
|
{
|
||||||
if ( (*i).first == (*j)->Name() )
|
if ( (*i).first == strtolower((*j)->Name()) )
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -434,7 +436,7 @@ Manager::bif_init_func_map* Manager::BifFilesInternal()
|
||||||
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
||||||
{
|
{
|
||||||
if ( a.first == b.first )
|
if ( a.first == b.first )
|
||||||
return a.second->Name() < a.second->Name();
|
return strtolower(a.second->Name()) < strtolower(a.second->Name());
|
||||||
|
|
||||||
// Reverse sort.
|
// Reverse sort.
|
||||||
return a.first > b.first;
|
return a.first > b.first;
|
||||||
|
|
|
@ -541,6 +541,13 @@ bool is_printable(const char* s, int len)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string strtolower(const std::string& s)
|
||||||
|
{
|
||||||
|
std::string t = s;
|
||||||
|
std::transform(t.begin(), t.end(), t.begin(), ::tolower);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
const char* fmt_bytes(const char* data, int len)
|
const char* fmt_bytes(const char* data, int len)
|
||||||
{
|
{
|
||||||
static char buf[1024];
|
static char buf[1024];
|
||||||
|
|
|
@ -159,6 +159,9 @@ int strstr_n(const int big_len, const unsigned char* big,
|
||||||
extern int fputs(int len, const char* s, FILE* fp);
|
extern int fputs(int len, const char* s, FILE* fp);
|
||||||
extern bool is_printable(const char* s, int len);
|
extern bool is_printable(const char* s, int len);
|
||||||
|
|
||||||
|
// Return a lower-cased version of the string.
|
||||||
|
extern std::string strtolower(const std::string& s);
|
||||||
|
|
||||||
extern const char* fmt_bytes(const char* data, int len);
|
extern const char* fmt_bytes(const char* data, int len);
|
||||||
|
|
||||||
// Note: returns a pointer into a shared buffer.
|
// Note: returns a pointer into a shared buffer.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue