zeek/src/ScannedFile.h
Robin Sommer fccb9ccab0
Re-instantiate providing location information to LoadFile hooks.
#1835 subtly changed the semantics of the `LoadFile` plugin hook to no
longer have the current script location available for signature files
being loaded through `@load-sigs`. This was undocumented behavior, so
it's technically not a regression, but since at least one external
plugin is depending on it, this change restores the old behavior.
2022-04-14 10:43:21 +02:00

52 lines
1.3 KiB
C++

// See the file "COPYING" in the main distribution directory for copyright.
#pragma once
#include <zeek/Obj.h>
#include <list>
#include <optional>
#include <string>
#include <vector>
namespace zeek::detail
{
// Script file we have already scanned (or are in the process of scanning).
// They are identified by normalized realpath.
class ScannedFile
{
public:
ScannedFile(int arg_include_level, std::string arg_name, bool arg_skipped = false,
bool arg_prefixes_checked = false);
/**
* Compares the canonical path of this file against every canonical path
* in files_scanned and returns whether there's any match.
*/
bool AlreadyScanned() const;
int include_level;
bool skipped; // This ScannedFile was @unload'd.
bool prefixes_checked; // If loading prefixes for this file has been tried.
std::string name;
std::string canonical_path; // normalized, absolute path via realpath()
static auto constexpr canonical_stdin_path = "<stdin>";
};
extern std::list<ScannedFile> files_scanned;
struct SignatureFile
{
std::string file;
std::optional<std::string> full_path;
Location load_location;
SignatureFile(std::string file);
SignatureFile(std::string file, std::string full_path, Location load_location);
};
extern std::vector<SignatureFile> sig_files;
} // namespace zeek::detail