mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 09:08:20 +00:00
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:
parent
7b8e7ed72c
commit
f5a76c1aed
786 changed files with 131714 additions and 153609 deletions
|
@ -14,172 +14,141 @@ using namespace btest::input::reader;
|
|||
using zeek::threading::Field;
|
||||
using zeek::threading::Value;
|
||||
|
||||
Foo::Foo(zeek::input::ReaderFrontend* frontend) : zeek::input::ReaderBackend(frontend)
|
||||
{
|
||||
ascii = new zeek::threading::formatter::Ascii(
|
||||
this, zeek::threading::formatter::Ascii::SeparatorInfo());
|
||||
}
|
||||
Foo::Foo(zeek::input::ReaderFrontend* frontend) : zeek::input::ReaderBackend(frontend) {
|
||||
ascii = new zeek::threading::formatter::Ascii(this, zeek::threading::formatter::Ascii::SeparatorInfo());
|
||||
}
|
||||
|
||||
Foo::~Foo()
|
||||
{
|
||||
DoClose();
|
||||
delete ascii;
|
||||
}
|
||||
Foo::~Foo() {
|
||||
DoClose();
|
||||
delete ascii;
|
||||
}
|
||||
|
||||
void Foo::DoClose() { }
|
||||
void Foo::DoClose() {}
|
||||
|
||||
bool Foo::DoInit(const zeek::input::ReaderBackend::ReaderInfo& info, int num_fields,
|
||||
const Field* const* fields)
|
||||
{
|
||||
DoUpdate();
|
||||
return true;
|
||||
}
|
||||
bool Foo::DoInit(const zeek::input::ReaderBackend::ReaderInfo& info, int num_fields, const Field* const* fields) {
|
||||
DoUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Foo::RandomString(const int len)
|
||||
{
|
||||
std::string s(len, ' ');
|
||||
std::string Foo::RandomString(const int len) {
|
||||
std::string s(len, ' ');
|
||||
|
||||
static const char values[] = "0123456789!@#$%^&*()-_=+{}[]\\|"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
static const char values[] =
|
||||
"0123456789!@#$%^&*()-_=+{}[]\\|"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
for ( int i = 0; i < len; ++i )
|
||||
// zeek::random_number() is not thread-safe; as we are only using one simultaneous thread
|
||||
// here, this should not matter in this case. If this test ever starts showing
|
||||
// random errors, this might be the culprit.
|
||||
s[i] = values[zeek::util::detail::random_number() /
|
||||
(zeek::util::detail::max_random() / sizeof(values))];
|
||||
for ( int i = 0; i < len; ++i )
|
||||
// zeek::random_number() is not thread-safe; as we are only using one simultaneous thread
|
||||
// here, this should not matter in this case. If this test ever starts showing
|
||||
// random errors, this might be the culprit.
|
||||
s[i] = values[zeek::util::detail::random_number() / (zeek::util::detail::max_random() / sizeof(values))];
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// read the entire file and send appropriate thingies back to InputMgr
|
||||
bool Foo::DoUpdate()
|
||||
{
|
||||
int linestosend = 5;
|
||||
for ( int i = 0; i < linestosend; i++ )
|
||||
{
|
||||
Value** field = new Value*[NumFields()];
|
||||
for ( int j = 0; j < NumFields(); j++ )
|
||||
field[j] = EntryToVal(Fields()[j]->type, Fields()[j]->subtype);
|
||||
bool Foo::DoUpdate() {
|
||||
int linestosend = 5;
|
||||
for ( int i = 0; i < linestosend; i++ ) {
|
||||
Value** field = new Value*[NumFields()];
|
||||
for ( int j = 0; j < NumFields(); j++ )
|
||||
field[j] = EntryToVal(Fields()[j]->type, Fields()[j]->subtype);
|
||||
|
||||
SendEntry(field);
|
||||
}
|
||||
SendEntry(field);
|
||||
}
|
||||
|
||||
EndCurrentSend();
|
||||
EndCurrentSend();
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
zeek::threading::Value* Foo::EntryToVal(zeek::TypeTag type, zeek::TypeTag subtype)
|
||||
{
|
||||
Value* val = new Value(type, true);
|
||||
zeek::threading::Value* Foo::EntryToVal(zeek::TypeTag type, zeek::TypeTag subtype) {
|
||||
Value* val = new Value(type, true);
|
||||
|
||||
// basically construct something random from the fields that we want.
|
||||
// basically construct something random from the fields that we want.
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case zeek::TYPE_ENUM:
|
||||
assert(false); // no enums, please.
|
||||
switch ( type ) {
|
||||
case zeek::TYPE_ENUM: assert(false); // no enums, please.
|
||||
|
||||
case zeek::TYPE_STRING:
|
||||
{
|
||||
std::string rnd = RandomString(10);
|
||||
val->val.string_val.data = zeek::util::copy_string(rnd.c_str());
|
||||
val->val.string_val.length = rnd.size();
|
||||
break;
|
||||
}
|
||||
case zeek::TYPE_STRING: {
|
||||
std::string rnd = RandomString(10);
|
||||
val->val.string_val.data = zeek::util::copy_string(rnd.c_str());
|
||||
val->val.string_val.length = rnd.size();
|
||||
break;
|
||||
}
|
||||
|
||||
case zeek::TYPE_BOOL:
|
||||
val->val.int_val = 1; // we never lie.
|
||||
break;
|
||||
case zeek::TYPE_BOOL:
|
||||
val->val.int_val = 1; // we never lie.
|
||||
break;
|
||||
|
||||
case zeek::TYPE_INT:
|
||||
val->val.int_val = random();
|
||||
break;
|
||||
case zeek::TYPE_INT: val->val.int_val = random(); break;
|
||||
|
||||
case zeek::TYPE_TIME:
|
||||
val->val.double_val = 0;
|
||||
break;
|
||||
case zeek::TYPE_TIME: val->val.double_val = 0; break;
|
||||
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_INTERVAL:
|
||||
val->val.double_val = random();
|
||||
break;
|
||||
case zeek::TYPE_DOUBLE:
|
||||
case zeek::TYPE_INTERVAL: val->val.double_val = random(); break;
|
||||
|
||||
case zeek::TYPE_COUNT:
|
||||
val->val.uint_val = random();
|
||||
break;
|
||||
case zeek::TYPE_COUNT: val->val.uint_val = random(); break;
|
||||
|
||||
case zeek::TYPE_PORT:
|
||||
val->val.port_val.port = random() / (RAND_MAX / 60000);
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
break;
|
||||
case zeek::TYPE_PORT:
|
||||
val->val.port_val.port = random() / (RAND_MAX / 60000);
|
||||
val->val.port_val.proto = TRANSPORT_UNKNOWN;
|
||||
break;
|
||||
|
||||
case zeek::TYPE_SUBNET:
|
||||
{
|
||||
val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1");
|
||||
val->val.subnet_val.length = 16;
|
||||
}
|
||||
break;
|
||||
case zeek::TYPE_SUBNET: {
|
||||
val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1");
|
||||
val->val.subnet_val.length = 16;
|
||||
} break;
|
||||
|
||||
case zeek::TYPE_ADDR:
|
||||
val->val.addr_val = ascii->ParseAddr("192.168.17.1");
|
||||
break;
|
||||
case zeek::TYPE_ADDR: val->val.addr_val = ascii->ParseAddr("192.168.17.1"); break;
|
||||
|
||||
case zeek::TYPE_TABLE:
|
||||
case zeek::TYPE_VECTOR:
|
||||
// First - common initialization
|
||||
// Then - initialization for table.
|
||||
// Then - initialization for vector.
|
||||
// Then - common stuff
|
||||
{
|
||||
// how many entries do we have...
|
||||
unsigned int length = random() / (RAND_MAX / 15);
|
||||
case zeek::TYPE_TABLE:
|
||||
case zeek::TYPE_VECTOR:
|
||||
// First - common initialization
|
||||
// Then - initialization for table.
|
||||
// Then - initialization for vector.
|
||||
// Then - common stuff
|
||||
{
|
||||
// how many entries do we have...
|
||||
unsigned int length = random() / (RAND_MAX / 15);
|
||||
|
||||
Value** lvals = new Value*[length];
|
||||
Value** lvals = new Value*[length];
|
||||
|
||||
if ( type == zeek::TYPE_TABLE )
|
||||
{
|
||||
val->val.set_val.vals = lvals;
|
||||
val->val.set_val.size = length;
|
||||
}
|
||||
else if ( type == zeek::TYPE_VECTOR )
|
||||
{
|
||||
val->val.vector_val.vals = lvals;
|
||||
val->val.vector_val.size = length;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
if ( type == zeek::TYPE_TABLE ) {
|
||||
val->val.set_val.vals = lvals;
|
||||
val->val.set_val.size = length;
|
||||
}
|
||||
else if ( type == zeek::TYPE_VECTOR ) {
|
||||
val->val.vector_val.vals = lvals;
|
||||
val->val.vector_val.size = length;
|
||||
}
|
||||
else
|
||||
assert(false);
|
||||
|
||||
if ( length == 0 )
|
||||
break; // empty
|
||||
if ( length == 0 )
|
||||
break; // empty
|
||||
|
||||
for ( unsigned int pos = 0; pos < length; pos++ )
|
||||
{
|
||||
Value* newval = EntryToVal(subtype, zeek::TYPE_ENUM);
|
||||
if ( newval == 0 )
|
||||
{
|
||||
Error("Error while reading set");
|
||||
delete val;
|
||||
return 0;
|
||||
}
|
||||
lvals[pos] = newval;
|
||||
}
|
||||
for ( unsigned int pos = 0; pos < length; pos++ ) {
|
||||
Value* newval = EntryToVal(subtype, zeek::TYPE_ENUM);
|
||||
if ( newval == 0 ) {
|
||||
Error("Error while reading set");
|
||||
delete val;
|
||||
return 0;
|
||||
}
|
||||
lvals[pos] = newval;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
Error(Fmt("unsupported field format %d", type));
|
||||
delete val;
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
Error(Fmt("unsupported field format %d", type));
|
||||
delete val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
bool Foo::DoHeartbeat(double network_time, double current_time)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Foo::DoHeartbeat(double network_time, double current_time) { return true; }
|
||||
|
|
|
@ -4,34 +4,29 @@
|
|||
#include "input/ReaderBackend.h"
|
||||
#include "threading/formatters/Ascii.h"
|
||||
|
||||
namespace btest::input::reader
|
||||
{
|
||||
namespace btest::input::reader {
|
||||
|
||||
/**
|
||||
* A Foo reader to measure performance of the input framework.
|
||||
*/
|
||||
class Foo : public zeek::input::ReaderBackend
|
||||
{
|
||||
class Foo : public zeek::input::ReaderBackend {
|
||||
public:
|
||||
Foo(zeek::input::ReaderFrontend* frontend);
|
||||
~Foo();
|
||||
Foo(zeek::input::ReaderFrontend* frontend);
|
||||
~Foo();
|
||||
|
||||
static zeek::input::ReaderBackend* Instantiate(zeek::input::ReaderFrontend* frontend)
|
||||
{
|
||||
return new Foo(frontend);
|
||||
}
|
||||
static zeek::input::ReaderBackend* Instantiate(zeek::input::ReaderFrontend* frontend) { return new Foo(frontend); }
|
||||
|
||||
protected:
|
||||
virtual bool DoInit(const zeek::input::ReaderBackend::ReaderInfo& info, int arg_num_fields,
|
||||
const zeek::threading::Field* const* fields);
|
||||
virtual void DoClose();
|
||||
virtual bool DoUpdate();
|
||||
virtual bool DoHeartbeat(double network_time, double current_time);
|
||||
virtual bool DoInit(const zeek::input::ReaderBackend::ReaderInfo& info, int arg_num_fields,
|
||||
const zeek::threading::Field* const* fields);
|
||||
virtual void DoClose();
|
||||
virtual bool DoUpdate();
|
||||
virtual bool DoHeartbeat(double network_time, double current_time);
|
||||
|
||||
private:
|
||||
std::string RandomString(const int len);
|
||||
zeek::threading::Value* EntryToVal(zeek::TypeTag Type, zeek::TypeTag subtype);
|
||||
zeek::threading::formatter::Ascii* ascii;
|
||||
};
|
||||
std::string RandomString(const int len);
|
||||
zeek::threading::Value* EntryToVal(zeek::TypeTag Type, zeek::TypeTag subtype);
|
||||
zeek::threading::formatter::Ascii* ascii;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace btest::input::reader
|
||||
|
|
|
@ -2,22 +2,20 @@
|
|||
|
||||
#include "Foo.h"
|
||||
|
||||
namespace btest::plugin::Demo_Foo
|
||||
{
|
||||
namespace btest::plugin::Demo_Foo {
|
||||
Plugin plugin;
|
||||
}
|
||||
}
|
||||
|
||||
using namespace btest::plugin::Demo_Foo;
|
||||
|
||||
zeek::plugin::Configuration Plugin::Configure()
|
||||
{
|
||||
AddComponent(new zeek::input::Component("Foo", btest::input::reader::Foo::Instantiate));
|
||||
zeek::plugin::Configuration Plugin::Configure() {
|
||||
AddComponent(new zeek::input::Component("Foo", btest::input::reader::Foo::Instantiate));
|
||||
|
||||
zeek::plugin::Configuration config;
|
||||
config.name = "Demo::Foo";
|
||||
config.description = "A Foo test input reader";
|
||||
config.version.major = 1;
|
||||
config.version.minor = 0;
|
||||
config.version.patch = 0;
|
||||
return config;
|
||||
}
|
||||
zeek::plugin::Configuration config;
|
||||
config.name = "Demo::Foo";
|
||||
config.description = "A Foo test input reader";
|
||||
config.version.major = 1;
|
||||
config.version.minor = 0;
|
||||
config.version.patch = 0;
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -3,16 +3,14 @@
|
|||
|
||||
#include <plugin/Plugin.h>
|
||||
|
||||
namespace btest::plugin::Demo_Foo
|
||||
{
|
||||
namespace btest::plugin::Demo_Foo {
|
||||
|
||||
class Plugin : public zeek::plugin::Plugin
|
||||
{
|
||||
class Plugin : public zeek::plugin::Plugin {
|
||||
protected:
|
||||
// Overridden from plugin::Plugin.
|
||||
virtual zeek::plugin::Configuration Configure();
|
||||
};
|
||||
// Overridden from plugin::Plugin.
|
||||
virtual zeek::plugin::Configuration Configure();
|
||||
};
|
||||
|
||||
extern Plugin plugin;
|
||||
|
||||
}
|
||||
} // namespace btest::plugin::Demo_Foo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue