mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 05:58: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
|
@ -15,485 +15,421 @@ using namespace std;
|
|||
using zeek::threading::Field;
|
||||
using zeek::threading::Value;
|
||||
|
||||
namespace zeek::input::reader::detail
|
||||
{
|
||||
namespace zeek::input::reader::detail {
|
||||
|
||||
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position)
|
||||
: name(arg_name), type(arg_type), subtype(TYPE_ERROR)
|
||||
{
|
||||
position = arg_position;
|
||||
secondary_position = -1;
|
||||
present = true;
|
||||
}
|
||||
: name(arg_name), type(arg_type), subtype(TYPE_ERROR) {
|
||||
position = arg_position;
|
||||
secondary_position = -1;
|
||||
present = true;
|
||||
}
|
||||
|
||||
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type,
|
||||
const TypeTag& arg_subtype, int arg_position)
|
||||
: name(arg_name), type(arg_type), subtype(arg_subtype)
|
||||
{
|
||||
position = arg_position;
|
||||
secondary_position = -1;
|
||||
present = true;
|
||||
}
|
||||
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype,
|
||||
int arg_position)
|
||||
: name(arg_name), type(arg_type), subtype(arg_subtype) {
|
||||
position = arg_position;
|
||||
secondary_position = -1;
|
||||
present = true;
|
||||
}
|
||||
|
||||
FieldMapping::FieldMapping(const FieldMapping& arg)
|
||||
: name(arg.name), type(arg.type), subtype(arg.subtype), present(arg.present)
|
||||
{
|
||||
position = arg.position;
|
||||
secondary_position = arg.secondary_position;
|
||||
}
|
||||
: name(arg.name), type(arg.type), subtype(arg.subtype), present(arg.present) {
|
||||
position = arg.position;
|
||||
secondary_position = arg.secondary_position;
|
||||
}
|
||||
|
||||
FieldMapping FieldMapping::subType()
|
||||
{
|
||||
return {name, subtype, position};
|
||||
}
|
||||
FieldMapping FieldMapping::subType() { return {name, subtype, position}; }
|
||||
|
||||
FieldMapping& FieldMapping::operator=(const FieldMapping& arg)
|
||||
{
|
||||
if ( this == &arg )
|
||||
return *this;
|
||||
FieldMapping& FieldMapping::operator=(const FieldMapping& arg) {
|
||||
if ( this == &arg )
|
||||
return *this;
|
||||
|
||||
name = arg.name;
|
||||
type = arg.type;
|
||||
subtype = arg.subtype;
|
||||
present = arg.present;
|
||||
position = arg.position;
|
||||
secondary_position = arg.secondary_position;
|
||||
name = arg.name;
|
||||
type = arg.type;
|
||||
subtype = arg.subtype;
|
||||
present = arg.present;
|
||||
position = arg.position;
|
||||
secondary_position = arg.secondary_position;
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Ascii::Ascii(ReaderFrontend* frontend) : ReaderBackend(frontend)
|
||||
{
|
||||
mtime = 0;
|
||||
ino = 0;
|
||||
fail_on_file_problem = false;
|
||||
fail_on_invalid_lines = false;
|
||||
}
|
||||
Ascii::Ascii(ReaderFrontend* frontend) : ReaderBackend(frontend) {
|
||||
mtime = 0;
|
||||
ino = 0;
|
||||
fail_on_file_problem = false;
|
||||
fail_on_invalid_lines = false;
|
||||
}
|
||||
|
||||
void Ascii::DoClose()
|
||||
{
|
||||
read_location.reset();
|
||||
}
|
||||
void Ascii::DoClose() { read_location.reset(); }
|
||||
|
||||
bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields)
|
||||
{
|
||||
StopWarningSuppression();
|
||||
bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields) {
|
||||
StopWarningSuppression();
|
||||
|
||||
separator.assign((const char*)BifConst::InputAscii::separator->Bytes(),
|
||||
BifConst::InputAscii::separator->Len());
|
||||
separator.assign((const char*)BifConst::InputAscii::separator->Bytes(), BifConst::InputAscii::separator->Len());
|
||||
|
||||
set_separator.assign((const char*)BifConst::InputAscii::set_separator->Bytes(),
|
||||
BifConst::InputAscii::set_separator->Len());
|
||||
set_separator.assign((const char*)BifConst::InputAscii::set_separator->Bytes(),
|
||||
BifConst::InputAscii::set_separator->Len());
|
||||
|
||||
empty_field.assign((const char*)BifConst::InputAscii::empty_field->Bytes(),
|
||||
BifConst::InputAscii::empty_field->Len());
|
||||
empty_field.assign((const char*)BifConst::InputAscii::empty_field->Bytes(),
|
||||
BifConst::InputAscii::empty_field->Len());
|
||||
|
||||
unset_field.assign((const char*)BifConst::InputAscii::unset_field->Bytes(),
|
||||
BifConst::InputAscii::unset_field->Len());
|
||||
unset_field.assign((const char*)BifConst::InputAscii::unset_field->Bytes(),
|
||||
BifConst::InputAscii::unset_field->Len());
|
||||
|
||||
fail_on_invalid_lines = BifConst::InputAscii::fail_on_invalid_lines;
|
||||
fail_on_file_problem = BifConst::InputAscii::fail_on_file_problem;
|
||||
fail_on_invalid_lines = BifConst::InputAscii::fail_on_invalid_lines;
|
||||
fail_on_file_problem = BifConst::InputAscii::fail_on_file_problem;
|
||||
|
||||
path_prefix.assign((const char*)BifConst::InputAscii::path_prefix->Bytes(),
|
||||
BifConst::InputAscii::path_prefix->Len());
|
||||
path_prefix.assign((const char*)BifConst::InputAscii::path_prefix->Bytes(),
|
||||
BifConst::InputAscii::path_prefix->Len());
|
||||
|
||||
// Set per-filter configuration options.
|
||||
for ( const auto& [k, v] : info.config )
|
||||
{
|
||||
if ( strcmp(k, "separator") == 0 )
|
||||
separator.assign(v);
|
||||
// Set per-filter configuration options.
|
||||
for ( const auto& [k, v] : info.config ) {
|
||||
if ( strcmp(k, "separator") == 0 )
|
||||
separator.assign(v);
|
||||
|
||||
else if ( strcmp(k, "set_separator") == 0 )
|
||||
set_separator.assign(v);
|
||||
else if ( strcmp(k, "set_separator") == 0 )
|
||||
set_separator.assign(v);
|
||||
|
||||
else if ( strcmp(k, "empty_field") == 0 )
|
||||
empty_field.assign(v);
|
||||
else if ( strcmp(k, "empty_field") == 0 )
|
||||
empty_field.assign(v);
|
||||
|
||||
else if ( strcmp(k, "unset_field") == 0 )
|
||||
unset_field.assign(v);
|
||||
else if ( strcmp(k, "unset_field") == 0 )
|
||||
unset_field.assign(v);
|
||||
|
||||
else if ( strcmp(k, "fail_on_invalid_lines") == 0 )
|
||||
fail_on_invalid_lines = (strncmp(v, "T", 1) == 0);
|
||||
else if ( strcmp(k, "fail_on_invalid_lines") == 0 )
|
||||
fail_on_invalid_lines = (strncmp(v, "T", 1) == 0);
|
||||
|
||||
else if ( strcmp(k, "fail_on_file_problem") == 0 )
|
||||
fail_on_file_problem = (strncmp(v, "T", 1) == 0);
|
||||
}
|
||||
else if ( strcmp(k, "fail_on_file_problem") == 0 )
|
||||
fail_on_file_problem = (strncmp(v, "T", 1) == 0);
|
||||
}
|
||||
|
||||
if ( separator.size() != 1 )
|
||||
Error("separator length has to be 1. Separator will be truncated.");
|
||||
if ( separator.size() != 1 )
|
||||
Error("separator length has to be 1. Separator will be truncated.");
|
||||
|
||||
if ( set_separator.size() != 1 )
|
||||
Error("set_separator length has to be 1. Separator will be truncated.");
|
||||
if ( set_separator.size() != 1 )
|
||||
Error("set_separator length has to be 1. Separator will be truncated.");
|
||||
|
||||
threading::formatter::Ascii::SeparatorInfo sep_info(separator, set_separator, unset_field,
|
||||
empty_field);
|
||||
formatter = unique_ptr<threading::Formatter>(new threading::formatter::Ascii(this, sep_info));
|
||||
threading::formatter::Ascii::SeparatorInfo sep_info(separator, set_separator, unset_field, empty_field);
|
||||
formatter = unique_ptr<threading::Formatter>(new threading::formatter::Ascii(this, sep_info));
|
||||
|
||||
return DoUpdate();
|
||||
}
|
||||
return DoUpdate();
|
||||
}
|
||||
|
||||
bool Ascii::OpenFile()
|
||||
{
|
||||
if ( file.is_open() )
|
||||
return true;
|
||||
bool Ascii::OpenFile() {
|
||||
if ( file.is_open() )
|
||||
return true;
|
||||
|
||||
// Handle path-prefixing. See similar logic in Binary::DoInit().
|
||||
fname = Info().source;
|
||||
// Handle path-prefixing. See similar logic in Binary::DoInit().
|
||||
fname = Info().source;
|
||||
|
||||
if ( fname.front() != '/' && ! path_prefix.empty() )
|
||||
{
|
||||
string path = path_prefix;
|
||||
std::size_t last = path.find_last_not_of('/');
|
||||
if ( fname.front() != '/' && ! path_prefix.empty() ) {
|
||||
string path = path_prefix;
|
||||
std::size_t last = path.find_last_not_of('/');
|
||||
|
||||
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
|
||||
path = "/";
|
||||
else
|
||||
path.erase(last + 1);
|
||||
if ( last == string::npos ) // Nothing but slashes -- weird but ok...
|
||||
path = "/";
|
||||
else
|
||||
path.erase(last + 1);
|
||||
|
||||
fname = path + "/" + fname;
|
||||
}
|
||||
fname = path + "/" + fname;
|
||||
}
|
||||
|
||||
file.open(fname);
|
||||
file.open(fname);
|
||||
|
||||
if ( ! file.is_open() )
|
||||
{
|
||||
FailWarn(fail_on_file_problem, Fmt("Init: cannot open %s", fname.c_str()), true);
|
||||
if ( ! file.is_open() ) {
|
||||
FailWarn(fail_on_file_problem, Fmt("Init: cannot open %s", fname.c_str()), true);
|
||||
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( ReadHeader(false) == false )
|
||||
{
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Init: cannot open %s; problem reading file header", fname.c_str()), true);
|
||||
if ( ReadHeader(false) == false ) {
|
||||
FailWarn(fail_on_file_problem, Fmt("Init: cannot open %s; problem reading file header", fname.c_str()), true);
|
||||
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( ! read_location )
|
||||
{
|
||||
read_location = LocationPtr(new zeek::detail::Location());
|
||||
read_location->filename = util::copy_string(fname.c_str());
|
||||
}
|
||||
if ( ! read_location ) {
|
||||
read_location = LocationPtr(new zeek::detail::Location());
|
||||
read_location->filename = util::copy_string(fname.c_str());
|
||||
}
|
||||
|
||||
StopWarningSuppression();
|
||||
return true;
|
||||
}
|
||||
StopWarningSuppression();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ascii::ReadHeader(bool useCached)
|
||||
{
|
||||
// try to read the header line...
|
||||
string line;
|
||||
bool Ascii::ReadHeader(bool useCached) {
|
||||
// try to read the header line...
|
||||
string line;
|
||||
|
||||
if ( ! useCached )
|
||||
{
|
||||
if ( ! GetLine(line) )
|
||||
{
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Could not read input data file %s; first line could not be read",
|
||||
fname.c_str()),
|
||||
true);
|
||||
return false;
|
||||
}
|
||||
if ( ! useCached ) {
|
||||
if ( ! GetLine(line) ) {
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Could not read input data file %s; first line could not be read", fname.c_str()), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
headerline = line;
|
||||
}
|
||||
headerline = line;
|
||||
}
|
||||
|
||||
else
|
||||
line = headerline;
|
||||
else
|
||||
line = headerline;
|
||||
|
||||
// construct list of field names.
|
||||
auto ifields = util::split(line, separator[0]);
|
||||
// construct list of field names.
|
||||
auto ifields = util::split(line, separator[0]);
|
||||
|
||||
// printf("Updating fields from description %s\n", line.c_str());
|
||||
columnMap.clear();
|
||||
// printf("Updating fields from description %s\n", line.c_str());
|
||||
columnMap.clear();
|
||||
|
||||
const auto* fields = Fields();
|
||||
const auto* fields = Fields();
|
||||
|
||||
for ( int i = 0; i < NumFields(); i++ )
|
||||
{
|
||||
const Field* field = fields[i];
|
||||
for ( int i = 0; i < NumFields(); i++ ) {
|
||||
const Field* field = fields[i];
|
||||
|
||||
auto fit = std::find(ifields.begin(), ifields.end(), field->name);
|
||||
if ( fit == ifields.end() )
|
||||
{
|
||||
if ( field->optional )
|
||||
{
|
||||
// we do not really need this field. mark it as not present and always send an undef
|
||||
// back.
|
||||
FieldMapping f(field->name, field->type, field->subtype, -1);
|
||||
f.present = false;
|
||||
columnMap.push_back(f);
|
||||
continue;
|
||||
}
|
||||
auto fit = std::find(ifields.begin(), ifields.end(), field->name);
|
||||
if ( fit == ifields.end() ) {
|
||||
if ( field->optional ) {
|
||||
// we do not really need this field. mark it as not present and always send an undef
|
||||
// back.
|
||||
FieldMapping f(field->name, field->type, field->subtype, -1);
|
||||
f.present = false;
|
||||
columnMap.push_back(f);
|
||||
continue;
|
||||
}
|
||||
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Did not find requested field %s in input data file %s.", field->name,
|
||||
fname.c_str()),
|
||||
true);
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Did not find requested field %s in input data file %s.", field->name, fname.c_str()), true);
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int index = static_cast<int>(std::distance(ifields.begin(), fit));
|
||||
FieldMapping f(field->name, field->type, field->subtype, index);
|
||||
int index = static_cast<int>(std::distance(ifields.begin(), fit));
|
||||
FieldMapping f(field->name, field->type, field->subtype, index);
|
||||
|
||||
if ( field->secondary_name && strlen(field->secondary_name) != 0 )
|
||||
{
|
||||
auto fit2 = std::find(ifields.begin(), ifields.end(), field->secondary_name);
|
||||
if ( fit2 == ifields.end() )
|
||||
{
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Could not find requested port type field %s in input data file %s.",
|
||||
field->secondary_name, fname.c_str()),
|
||||
true);
|
||||
if ( field->secondary_name && strlen(field->secondary_name) != 0 ) {
|
||||
auto fit2 = std::find(ifields.begin(), ifields.end(), field->secondary_name);
|
||||
if ( fit2 == ifields.end() ) {
|
||||
FailWarn(fail_on_file_problem,
|
||||
Fmt("Could not find requested port type field %s in input data file %s.",
|
||||
field->secondary_name, fname.c_str()),
|
||||
true);
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
f.secondary_position = static_cast<int>(std::distance(ifields.begin(), fit2));
|
||||
}
|
||||
f.secondary_position = static_cast<int>(std::distance(ifields.begin(), fit2));
|
||||
}
|
||||
|
||||
columnMap.push_back(f);
|
||||
}
|
||||
columnMap.push_back(f);
|
||||
}
|
||||
|
||||
// well, that seems to have worked...
|
||||
return true;
|
||||
}
|
||||
// well, that seems to have worked...
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ascii::GetLine(string& str)
|
||||
{
|
||||
while ( getline(file, str) )
|
||||
{
|
||||
if ( read_location )
|
||||
{
|
||||
read_location->first_line++;
|
||||
read_location->last_line++;
|
||||
}
|
||||
bool Ascii::GetLine(string& str) {
|
||||
while ( getline(file, str) ) {
|
||||
if ( read_location ) {
|
||||
read_location->first_line++;
|
||||
read_location->last_line++;
|
||||
}
|
||||
|
||||
if ( str.empty() )
|
||||
continue;
|
||||
if ( str.empty() )
|
||||
continue;
|
||||
|
||||
if ( str.back() == '\r' ) // deal with \r\n by removing \r
|
||||
str.pop_back();
|
||||
if ( str.back() == '\r' ) // deal with \r\n by removing \r
|
||||
str.pop_back();
|
||||
|
||||
if ( str[0] != '#' )
|
||||
return true;
|
||||
if ( str[0] != '#' )
|
||||
return true;
|
||||
|
||||
if ( (str.length() > 8) && (str.compare(0, 7, "#fields") == 0) && (str[7] == separator[0]) )
|
||||
{
|
||||
str = str.substr(8);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ( (str.length() > 8) && (str.compare(0, 7, "#fields") == 0) && (str[7] == separator[0]) ) {
|
||||
str = str.substr(8);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// read the entire file and send appropriate thingies back to InputMgr
|
||||
bool Ascii::DoUpdate()
|
||||
{
|
||||
if ( ! OpenFile() )
|
||||
return ! fail_on_file_problem;
|
||||
bool Ascii::DoUpdate() {
|
||||
if ( ! OpenFile() )
|
||||
return ! fail_on_file_problem;
|
||||
|
||||
if ( read_location )
|
||||
{
|
||||
read_location->first_line = 0;
|
||||
read_location->last_line = 0;
|
||||
}
|
||||
if ( read_location ) {
|
||||
read_location->first_line = 0;
|
||||
read_location->last_line = 0;
|
||||
}
|
||||
|
||||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_REREAD:
|
||||
{
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 )
|
||||
{
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()),
|
||||
true);
|
||||
switch ( Info().mode ) {
|
||||
case MODE_REREAD: {
|
||||
// check if the file has changed
|
||||
struct stat sb;
|
||||
if ( stat(fname.c_str(), &sb) == -1 ) {
|
||||
FailWarn(fail_on_file_problem, Fmt("Could not get stat for %s", fname.c_str()), true);
|
||||
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
file.close();
|
||||
return ! fail_on_file_problem;
|
||||
}
|
||||
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
if ( sb.st_ino == ino && sb.st_mtime == mtime )
|
||||
// no change
|
||||
return true;
|
||||
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
// Warn again in case of trouble if the file changes. The comparison to 0
|
||||
// is to suppress an extra warning that we'd otherwise get on the initial
|
||||
// inode assignment.
|
||||
if ( ino != 0 )
|
||||
StopWarningSuppression();
|
||||
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
}
|
||||
mtime = sb.st_mtime;
|
||||
ino = sb.st_ino;
|
||||
// File changed. Fall through to re-read.
|
||||
}
|
||||
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM:
|
||||
{
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() )
|
||||
{
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
{
|
||||
file.clear(); // remove end of file evil bits
|
||||
if ( ! ReadHeader(true) )
|
||||
{
|
||||
return ! fail_on_file_problem; // header reading failed
|
||||
}
|
||||
case MODE_MANUAL:
|
||||
case MODE_STREAM: {
|
||||
// dirty, fix me. (well, apparently after trying seeking, etc
|
||||
// - this is not that bad)
|
||||
if ( file.is_open() ) {
|
||||
if ( Info().mode == MODE_STREAM ) {
|
||||
file.clear(); // remove end of file evil bits
|
||||
if ( ! ReadHeader(true) ) {
|
||||
return ! fail_on_file_problem; // header reading failed
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
OpenFile();
|
||||
OpenFile();
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
string line;
|
||||
string line;
|
||||
|
||||
file.sync();
|
||||
file.sync();
|
||||
|
||||
while ( GetLine(line) )
|
||||
{
|
||||
// split on tabs
|
||||
bool error = false;
|
||||
auto stringfields = util::split(line, separator[0]);
|
||||
while ( GetLine(line) ) {
|
||||
// split on tabs
|
||||
bool error = false;
|
||||
auto stringfields = util::split(line, separator[0]);
|
||||
|
||||
// This needs to be a signed value or the comparisons below will fail.
|
||||
int pos = static_cast<int>(stringfields.size() - 1);
|
||||
// This needs to be a signed value or the comparisons below will fail.
|
||||
int pos = static_cast<int>(stringfields.size() - 1);
|
||||
|
||||
Value** fields = new Value*[NumFields()];
|
||||
Value** fields = new Value*[NumFields()];
|
||||
|
||||
int fpos = 0;
|
||||
for ( const auto& fit : columnMap )
|
||||
{
|
||||
if ( ! fit.present )
|
||||
{
|
||||
// add non-present field
|
||||
fields[fpos] = new Value(fit.type, false);
|
||||
if ( read_location )
|
||||
fields[fpos]->SetFileLineNumber(read_location->first_line);
|
||||
fpos++;
|
||||
continue;
|
||||
}
|
||||
int fpos = 0;
|
||||
for ( const auto& fit : columnMap ) {
|
||||
if ( ! fit.present ) {
|
||||
// add non-present field
|
||||
fields[fpos] = new Value(fit.type, false);
|
||||
if ( read_location )
|
||||
fields[fpos]->SetFileLineNumber(read_location->first_line);
|
||||
fpos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
assert(fit.position >= 0);
|
||||
assert(fit.position >= 0);
|
||||
|
||||
if ( fit.position > pos || fit.secondary_position > pos )
|
||||
{
|
||||
FailWarn(fail_on_invalid_lines, Fmt("Not enough fields in line '%s' of %s. Found "
|
||||
"%d fields, want positions %d and %d",
|
||||
line.c_str(), fname.c_str(), pos, fit.position,
|
||||
fit.secondary_position));
|
||||
if ( fit.position > pos || fit.secondary_position > pos ) {
|
||||
FailWarn(fail_on_invalid_lines,
|
||||
Fmt("Not enough fields in line '%s' of %s. Found "
|
||||
"%d fields, want positions %d and %d",
|
||||
line.c_str(), fname.c_str(), pos, fit.position, fit.secondary_position));
|
||||
|
||||
if ( fail_on_invalid_lines )
|
||||
{
|
||||
for ( int i = 0; i < fpos; i++ )
|
||||
delete fields[i];
|
||||
if ( fail_on_invalid_lines ) {
|
||||
for ( int i = 0; i < fpos; i++ )
|
||||
delete fields[i];
|
||||
|
||||
delete[] fields;
|
||||
delete[] fields;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Value* val = formatter->ParseValue(stringfields[fit.position], fit.name, fit.type,
|
||||
fit.subtype);
|
||||
if ( ! val )
|
||||
{
|
||||
Warning(Fmt("Could not convert line '%s' of %s to Val. Ignoring line.",
|
||||
line.c_str(), fname.c_str()));
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
Value* val = formatter->ParseValue(stringfields[fit.position], fit.name, fit.type, fit.subtype);
|
||||
if ( ! val ) {
|
||||
Warning(Fmt("Could not convert line '%s' of %s to Val. Ignoring line.", line.c_str(), fname.c_str()));
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( read_location )
|
||||
val->SetFileLineNumber(read_location->first_line);
|
||||
if ( read_location )
|
||||
val->SetFileLineNumber(read_location->first_line);
|
||||
|
||||
if ( fit.secondary_position != -1 )
|
||||
{
|
||||
// we have a port definition :)
|
||||
assert(val->type == TYPE_PORT);
|
||||
// Error(Fmt("Got type %d != PORT with secondary position!", val->type));
|
||||
if ( fit.secondary_position != -1 ) {
|
||||
// we have a port definition :)
|
||||
assert(val->type == TYPE_PORT);
|
||||
// Error(Fmt("Got type %d != PORT with secondary position!", val->type));
|
||||
|
||||
val->val.port_val.proto = formatter->ParseProto(
|
||||
stringfields[fit.secondary_position]);
|
||||
}
|
||||
val->val.port_val.proto = formatter->ParseProto(stringfields[fit.secondary_position]);
|
||||
}
|
||||
|
||||
fields[fpos] = val;
|
||||
fields[fpos] = val;
|
||||
|
||||
fpos++;
|
||||
}
|
||||
fpos++;
|
||||
}
|
||||
|
||||
if ( error )
|
||||
{
|
||||
// Encountered non-fatal error, ignoring line. But
|
||||
// first, delete all successfully read fields and the
|
||||
// array structure.
|
||||
if ( error ) {
|
||||
// Encountered non-fatal error, ignoring line. But
|
||||
// first, delete all successfully read fields and the
|
||||
// array structure.
|
||||
|
||||
for ( int i = 0; i < fpos; i++ )
|
||||
delete fields[i];
|
||||
for ( int i = 0; i < fpos; i++ )
|
||||
delete fields[i];
|
||||
|
||||
delete[] fields;
|
||||
continue;
|
||||
}
|
||||
delete[] fields;
|
||||
continue;
|
||||
}
|
||||
|
||||
// printf("fpos: %d, second.num_fields: %d\n", fpos, (*it).second.num_fields);
|
||||
assert(fpos == NumFields());
|
||||
// printf("fpos: %d, second.num_fields: %d\n", fpos, (*it).second.num_fields);
|
||||
assert(fpos == NumFields());
|
||||
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
Put(fields);
|
||||
else
|
||||
SendEntry(fields);
|
||||
}
|
||||
if ( Info().mode == MODE_STREAM )
|
||||
Put(fields);
|
||||
else
|
||||
SendEntry(fields);
|
||||
}
|
||||
|
||||
if ( Info().mode != MODE_STREAM )
|
||||
EndCurrentSend();
|
||||
if ( Info().mode != MODE_STREAM )
|
||||
EndCurrentSend();
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ascii::DoHeartbeat(double network_time, double current_time)
|
||||
{
|
||||
if ( ! OpenFile() )
|
||||
return ! fail_on_file_problem;
|
||||
bool Ascii::DoHeartbeat(double network_time, double current_time) {
|
||||
if ( ! OpenFile() )
|
||||
return ! fail_on_file_problem;
|
||||
|
||||
switch ( Info().mode )
|
||||
{
|
||||
case MODE_MANUAL:
|
||||
// yay, we do nothing :)
|
||||
break;
|
||||
switch ( Info().mode ) {
|
||||
case MODE_MANUAL:
|
||||
// yay, we do nothing :)
|
||||
break;
|
||||
|
||||
case MODE_REREAD:
|
||||
case MODE_STREAM:
|
||||
Update(); // Call Update, not DoUpdate, because Update
|
||||
// checks the "disabled" flag.
|
||||
break;
|
||||
case MODE_REREAD:
|
||||
case MODE_STREAM:
|
||||
Update(); // Call Update, not DoUpdate, because Update
|
||||
// checks the "disabled" flag.
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
default: assert(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace zeek::input::reader::detail
|
||||
} // namespace zeek::input::reader::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue