GH-237: add @load foo.bro -> foo.zeek fallback

When failing to locate a script with explicit .bro suffix, check for
whether one with a .zeek suffix exists and use it instead.
This commit is contained in:
Jon Siwek 2019-04-16 17:44:31 -07:00
parent 8f82ecc66d
commit f21e11d811
6 changed files with 43 additions and 5 deletions

View file

@ -1298,6 +1298,14 @@ string find_file(const string& filename, const string& path_set,
return string();
}
static bool ends_with(const std::string& s, const std::string& ending)
{
if ( ending.size() > s.size() )
return false;
return std::equal(ending.rbegin(), ending.rend(), s.rbegin());
}
string find_script_file(const string& filename, const string& path_set)
{
vector<string> paths;
@ -1313,6 +1321,14 @@ string find_script_file(const string& filename, const string& path_set)
return f;
}
if ( ends_with(filename, ".bro") )
{
// We were looking for a file explicitly ending in .bro and didn't
// find it, so fall back to one ending in .zeek, if it exists.
auto fallback = string(filename.data(), filename.size() - 4) + ".zeek";
return find_script_file(fallback, path_set);
}
return string();
}