Reformat Zeek in Spicy style

This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
This commit is contained in:
Benjamin Bannier 2023-10-10 21:13:34 +02:00
parent 7b8e7ed72c
commit f5a76c1aed
786 changed files with 131714 additions and 153609 deletions

View file

@ -1,43 +1,37 @@
#include "Plugin.h"
namespace btest::plugin::Testing_LoadFileExtended
{
namespace btest::plugin::Testing_LoadFileExtended {
Plugin plugin;
}
}
using namespace btest::plugin::Testing_LoadFileExtended;
zeek::plugin::Configuration Plugin::Configure()
{
EnableHook(zeek::plugin::HOOK_LOAD_FILE_EXT);
zeek::plugin::Configuration Plugin::Configure() {
EnableHook(zeek::plugin::HOOK_LOAD_FILE_EXT);
zeek::plugin::Configuration config;
config.name = "Testing::LoadFileExtended";
config.version.major = 0;
config.version.minor = 1;
config.version.patch = 4;
return config;
}
zeek::plugin::Configuration config;
config.name = "Testing::LoadFileExtended";
config.version.major = 0;
config.version.minor = 1;
config.version.patch = 4;
return config;
}
#include <iostream>
std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const LoadType type,
const std::string& file,
const std::string& resolved)
{
// Zeek implicitly provides the location where the current '@load'
// originated. If no location is available, filename will be a nullptr.
auto src = zeek::detail::GetCurrentLocation().filename;
if ( ! src )
src = "n/a";
std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const LoadType type, const std::string& file,
const std::string& resolved) {
// Zeek implicitly provides the location where the current '@load'
// originated. If no location is available, filename will be a nullptr.
auto src = zeek::detail::GetCurrentLocation().filename;
if ( ! src )
src = "n/a";
if ( type == LoadType::SCRIPT && file == "xxx" )
{
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(),
resolved.c_str(), src);
if ( type == LoadType::SCRIPT && file == "xxx" ) {
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
return std::make_pair(1, R"(
return std::make_pair(1, R"(
event zeek_init() {
print "new zeek_init(): script has been replaced";
}
@ -46,49 +40,43 @@ std::pair<int, std::optional<std::string>> Plugin::HookLoadFileExtended(const Lo
print msg;
}
)");
}
}
if ( type == LoadType::SCRIPT && file == "xxx3" )
{
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(),
resolved.c_str(), src);
// We don't replace this one.
return std::make_pair(-1, std::nullopt);
}
if ( type == LoadType::SCRIPT && file == "xxx3" ) {
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
// We don't replace this one.
return std::make_pair(-1, std::nullopt);
}
if ( type == LoadType::SCRIPT && file == "yyy" )
{
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(),
resolved.c_str(), src);
if ( type == LoadType::SCRIPT && file == "yyy" ) {
printf("HookLoadExtended/script: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(), src);
return std::make_pair(1, R"(
return std::make_pair(1, R"(
event zeek_init() {
print "new zeek_init(): script has been added";
}
)");
}
}
if ( type == LoadType::SIGNATURES && file == "abc.sig" )
{
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(),
resolved.c_str(), src);
if ( type == LoadType::SIGNATURES && file == "abc.sig" ) {
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(),
src);
return std::make_pair(1, R"(
return std::make_pair(1, R"(
signature my-sig {
ip-proto == tcp
payload /GET \/images/
event "signature works!"
}
)");
}
}
if ( type == LoadType::SIGNATURES && file == "def.sig" )
{
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(),
resolved.c_str(), src);
// We don't replace this one.
return std::make_pair(-1, std::nullopt);
}
if ( type == LoadType::SIGNATURES && file == "def.sig" ) {
printf("HookLoadExtended/signature: file=|%s| resolved=|%s| srcloc=|%s|\n", file.c_str(), resolved.c_str(),
src);
// We don't replace this one.
return std::make_pair(-1, std::nullopt);
}
return std::make_pair(-1, std::nullopt);
}
return std::make_pair(-1, std::nullopt);
}

View file

@ -3,19 +3,17 @@
#include <zeek/plugin/Plugin.h>
namespace btest::plugin::Testing_LoadFileExtended
{
namespace btest::plugin::Testing_LoadFileExtended {
class Plugin : public zeek::plugin::Plugin
{
class Plugin : public zeek::plugin::Plugin {
protected:
// Overridden from zeek::plugin::Plugin.
zeek::plugin::Configuration Configure() override;
std::pair<int, std::optional<std::string>>
HookLoadFileExtended(const Plugin::LoadType type, const std::string& file,
const std::string& resolved) override;
};
// Overridden from zeek::plugin::Plugin.
zeek::plugin::Configuration Configure() override;
std::pair<int, std::optional<std::string>> HookLoadFileExtended(const Plugin::LoadType type,
const std::string& file,
const std::string& resolved) override;
};
extern Plugin plugin;
}
} // namespace btest::plugin::Testing_LoadFileExtended