mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
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:
parent
8f82ecc66d
commit
f21e11d811
6 changed files with 43 additions and 5 deletions
7
CHANGES
7
CHANGES
|
@ -1,4 +1,11 @@
|
||||||
|
|
||||||
|
2.6-227 | 2019-04-16 17:44:31 -0700
|
||||||
|
|
||||||
|
* GH-237: add `@load foo.bro` -> foo.zeek fallback (Jon Siwek, Corelight)
|
||||||
|
|
||||||
|
When failing to locate a script with explicit .bro suffix, check for
|
||||||
|
whether one with a .zeek suffix exists and use it instead.
|
||||||
|
|
||||||
2.6-225 | 2019-04-16 16:07:49 -0700
|
2.6-225 | 2019-04-16 16:07:49 -0700
|
||||||
|
|
||||||
* Use .zeek file suffix in unit tests (Jon Siwek, Corelight)
|
* Use .zeek file suffix in unit tests (Jon Siwek, Corelight)
|
||||||
|
|
10
NEWS
10
NEWS
|
@ -81,10 +81,12 @@ Changed Functionality
|
||||||
been renamed to ``.zeek``.
|
been renamed to ``.zeek``.
|
||||||
|
|
||||||
- The search logic for the ``@load`` script directive now prefers files
|
- The search logic for the ``@load`` script directive now prefers files
|
||||||
ending in ``.zeek``, but will fallback to loading a ``.bro`` file if it
|
ending in ``.zeek``, but will fallback to loading a ``.bro`` file if
|
||||||
exists. E.g. ``@load foo`` will check for ``foo.zeek`` and then ``foo.bro``.
|
it exists. E.g. ``@load foo`` will first check for a ``foo.zeek``
|
||||||
Note that ``@load foo.bro`` will not automatically check for
|
file to load and then otherwise ``foo.bro``. Note that
|
||||||
``@load foo.zeek``.
|
``@load foo.bro`` (with the explicit ``.bro`` file suffix) prefers
|
||||||
|
in the opposite order: it first checks for ``foo.bro`` and then
|
||||||
|
falls back to a ``foo.zeek``, if it exists.
|
||||||
|
|
||||||
- The for-loop index variable for vectors has been changed from
|
- The for-loop index variable for vectors has been changed from
|
||||||
'int' to 'count' type. It's unlikely this would alter/break any
|
'int' to 'count' type. It's unlikely this would alter/break any
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.6-225
|
2.6-227
|
||||||
|
|
16
src/util.cc
16
src/util.cc
|
@ -1298,6 +1298,14 @@ string find_file(const string& filename, const string& path_set,
|
||||||
return string();
|
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)
|
string find_script_file(const string& filename, const string& path_set)
|
||||||
{
|
{
|
||||||
vector<string> paths;
|
vector<string> paths;
|
||||||
|
@ -1313,6 +1321,14 @@ string find_script_file(const string& filename, const string& path_set)
|
||||||
return f;
|
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();
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
loaded foo.zeek
|
12
testing/btest/core/load-explicit-bro-suffix-fallback.zeek
Normal file
12
testing/btest/core/load-explicit-bro-suffix-fallback.zeek
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# @TEST-EXEC: bro -b %INPUT >out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
# We don't have a foo.bro, but we'll accept foo.zeek.
|
||||||
|
@load foo.bro
|
||||||
|
|
||||||
|
@TEST-START-FILE foo.zeek
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
print "loaded foo.zeek";
|
||||||
|
}
|
||||||
|
@TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue