mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Fixing Broxygen indexing confusion for plugins.
Because plugins register their script directories with the BROPATH, Broxygen stripped them out from plugin script paths it was indexing. That then led to multiple plugins ending up with the same script paths, triggering warnings about duplicates. I fixed this by checking if a script comes out of a plugin. If so, it gets an artifcial index prefix "<plugin-name>:", followed by the script's relative path inside the plugin's top-level directory. For example, "/opt/bro/lib/bro/plugins/Bro_Netmap/scripts/init.bro" now turns into "Bro::Netmap:scripts/init.bro" for Broxygen purposes (whereas it used to be just "init.bro"). Addresses BIT-1663. (Can't think of a good way to add a test for this unfortunately.)
This commit is contained in:
parent
b6a0802227
commit
8acf995361
3 changed files with 61 additions and 10 deletions
|
@ -240,6 +240,8 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
|
|||
current_plugin->DoConfigure();
|
||||
current_plugin->InitializeComponents();
|
||||
|
||||
plugins_by_path.insert(std::make_pair(normalize_path(dir), current_plugin));
|
||||
|
||||
if ( current_plugin->APIVersion() != BRO_PLUGIN_API_VERSION )
|
||||
reporter->FatalError("plugin's API version does not match Bro (expected %d, got %d in %s)",
|
||||
BRO_PLUGIN_API_VERSION, current_plugin->APIVersion(), path);
|
||||
|
@ -327,7 +329,7 @@ void Manager::RegisterPlugin(Plugin *plugin)
|
|||
|
||||
if ( current_dir && current_sopath )
|
||||
// A dynamic plugin, record its location.
|
||||
plugin->SetPluginLocation(current_dir, current_sopath);
|
||||
plugin->SetPluginLocation(normalize_path(current_dir), current_sopath);
|
||||
|
||||
current_plugin = plugin;
|
||||
}
|
||||
|
@ -462,6 +464,31 @@ Manager::bif_init_func_map* Manager::BifFilesInternal()
|
|||
return bifs;
|
||||
}
|
||||
|
||||
Plugin* Manager::LookupPluginByPath(std::string path)
|
||||
{
|
||||
path = normalize_path(path);
|
||||
|
||||
if ( is_file(path) )
|
||||
path = SafeDirname(path).result;
|
||||
|
||||
while ( path.size() )
|
||||
{
|
||||
auto i = plugins_by_path.find(path);
|
||||
|
||||
if ( i != plugins_by_path.end() )
|
||||
return i->second;
|
||||
|
||||
auto j = path.rfind("/");
|
||||
|
||||
if ( j == std::string::npos )
|
||||
break;
|
||||
|
||||
path.erase(j);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool hook_cmp(std::pair<int, Plugin*> a, std::pair<int, Plugin*> b)
|
||||
{
|
||||
if ( a.first == b.first )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue