Update script search logic for new file extension

When searching for script files, look for both the new and old file
extensions.  If a file with ".zeek" can't be found, then search for
a file with ".bro" as a fallback.
This commit is contained in:
Daniel Thayer 2019-04-09 01:26:16 -05:00
parent bff8392ad4
commit 7366155bad
9 changed files with 129 additions and 43 deletions

View file

@ -26,6 +26,7 @@
#include <stdint.h>
#include <string>
#include <array>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
@ -248,16 +249,16 @@ static const SourceID SOURCE_BROKER = 0xffffffff;
extern void pinpoint();
extern int int_list_cmp(const void* v1, const void* v2);
// Contains the name of the script file that gets read
// when a package is loaded (i.e., "__load__.bro).
extern const char* PACKAGE_LOADER;
extern const std::string& bro_path();
extern const char* bro_magic_path();
extern const char* bro_plugin_path();
extern const char* bro_plugin_activate();
extern std::string bro_prefixes();
extern const std::array<std::string, 2> script_extensions;
bool is_package_loader(const std::string& path);
extern void add_to_bro_path(const std::string& dir);
@ -341,6 +342,14 @@ std::string without_bropath_component(const std::string& path);
std::string find_file(const std::string& filename, const std::string& path_set,
const std::string& opt_ext = "");
/**
* Locate a script file within a given search path.
* @param filename Name of a file to find.
* @param path_set Colon-delimited set of paths to search for the file.
* @return Path to the found file, or an empty string if not found.
*/
std::string find_script_file(const std::string& filename, const std::string& path_set);
// Wrapper around fopen(3). Emits an error when failing to open.
FILE* open_file(const std::string& path, const std::string& mode = "r");