mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 19:18:19 +00:00
In progress on ascii writer behavior change.
This commit is contained in:
parent
205a28bad8
commit
b0d812812f
2 changed files with 69 additions and 19 deletions
|
@ -61,6 +61,11 @@ void Ascii::DoClose()
|
||||||
|
|
||||||
bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields)
|
bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields)
|
||||||
{
|
{
|
||||||
|
continue_on_failure = true;
|
||||||
|
is_failed = false;
|
||||||
|
|
||||||
|
filename = info.source;
|
||||||
|
|
||||||
separator.assign( (const char*) BifConst::InputAscii::separator->Bytes(),
|
separator.assign( (const char*) BifConst::InputAscii::separator->Bytes(),
|
||||||
BifConst::InputAscii::separator->Len());
|
BifConst::InputAscii::separator->Len());
|
||||||
|
|
||||||
|
@ -98,18 +103,10 @@ bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* f
|
||||||
formatter::Ascii::SeparatorInfo sep_info(separator, set_separator, unset_field, empty_field);
|
formatter::Ascii::SeparatorInfo sep_info(separator, set_separator, unset_field, empty_field);
|
||||||
formatter = unique_ptr<threading::formatter::Formatter>(new formatter::Ascii(this, sep_info));
|
formatter = unique_ptr<threading::formatter::Formatter>(new formatter::Ascii(this, sep_info));
|
||||||
|
|
||||||
file.open(info.source);
|
if ( ! OpenFile() )
|
||||||
if ( ! file.is_open() )
|
|
||||||
{
|
{
|
||||||
Error(Fmt("Init: cannot open %s", info.source));
|
is_failed = true;
|
||||||
return false;
|
return continue_on_failure;
|
||||||
}
|
|
||||||
|
|
||||||
if ( ReadHeader(false) == false )
|
|
||||||
{
|
|
||||||
Error(Fmt("Init: cannot open %s; headers are incorrect", info.source));
|
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DoUpdate();
|
DoUpdate();
|
||||||
|
@ -117,6 +114,26 @@ bool Ascii::DoInit(const ReaderInfo& info, int num_fields, const Field* const* f
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Ascii::OpenFile()
|
||||||
|
{
|
||||||
|
file.open(filename);
|
||||||
|
if ( ! file.is_open() )
|
||||||
|
{
|
||||||
|
Error(Fmt("Init: cannot open %s", filename.c_str()));
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ReadHeader(false) == false )
|
||||||
|
{
|
||||||
|
Error(Fmt("Init: cannot open %s; headers are incorrect", filename.c_str()));
|
||||||
|
file.close();
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Ascii::ReadHeader(bool useCached)
|
bool Ascii::ReadHeader(bool useCached)
|
||||||
{
|
{
|
||||||
|
@ -129,7 +146,8 @@ bool Ascii::ReadHeader(bool useCached)
|
||||||
if ( ! GetLine(line) )
|
if ( ! GetLine(line) )
|
||||||
{
|
{
|
||||||
Error("could not read first line");
|
Error("could not read first line");
|
||||||
return false;
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
headerline = line;
|
headerline = line;
|
||||||
|
@ -172,7 +190,9 @@ bool Ascii::ReadHeader(bool useCached)
|
||||||
|
|
||||||
Error(Fmt("Did not find requested field %s in input data file %s.",
|
Error(Fmt("Did not find requested field %s in input data file %s.",
|
||||||
field->name, Info().source));
|
field->name, Info().source));
|
||||||
return false;
|
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapping f(field->name, field->type, field->subtype, ifields[field->name]);
|
FieldMapping f(field->name, field->type, field->subtype, ifields[field->name]);
|
||||||
|
@ -184,7 +204,9 @@ bool Ascii::ReadHeader(bool useCached)
|
||||||
{
|
{
|
||||||
Error(Fmt("Could not find requested port type field %s in input data file.",
|
Error(Fmt("Could not find requested port type field %s in input data file.",
|
||||||
field->secondary_name));
|
field->secondary_name));
|
||||||
return false;
|
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
f.secondary_position = ifields[field->secondary_name];
|
f.secondary_position = ifields[field->secondary_name];
|
||||||
|
@ -224,6 +246,12 @@ bool Ascii::GetLine(string& str)
|
||||||
// read the entire file and send appropriate thingies back to InputMgr
|
// read the entire file and send appropriate thingies back to InputMgr
|
||||||
bool Ascii::DoUpdate()
|
bool Ascii::DoUpdate()
|
||||||
{
|
{
|
||||||
|
if ( is_failed )
|
||||||
|
if ( ! OpenFile() )
|
||||||
|
{
|
||||||
|
printf("do updates after failure?!\n");
|
||||||
|
}
|
||||||
|
|
||||||
switch ( Info().mode ) {
|
switch ( Info().mode ) {
|
||||||
case MODE_REREAD:
|
case MODE_REREAD:
|
||||||
{
|
{
|
||||||
|
@ -232,7 +260,8 @@ bool Ascii::DoUpdate()
|
||||||
if ( stat(Info().source, &sb) == -1 )
|
if ( stat(Info().source, &sb) == -1 )
|
||||||
{
|
{
|
||||||
Error(Fmt("Could not get stat for %s", Info().source));
|
Error(Fmt("Could not get stat for %s", Info().source));
|
||||||
return false;
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( sb.st_mtime <= mtime ) // no change
|
if ( sb.st_mtime <= mtime ) // no change
|
||||||
|
@ -255,7 +284,10 @@ bool Ascii::DoUpdate()
|
||||||
{
|
{
|
||||||
file.clear(); // remove end of file evil bits
|
file.clear(); // remove end of file evil bits
|
||||||
if ( !ReadHeader(true) )
|
if ( !ReadHeader(true) )
|
||||||
return false; // header reading failed
|
{
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure; // header reading failed
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -267,12 +299,14 @@ bool Ascii::DoUpdate()
|
||||||
if ( ! file.is_open() )
|
if ( ! file.is_open() )
|
||||||
{
|
{
|
||||||
Error(Fmt("cannot open %s", Info().source));
|
Error(Fmt("cannot open %s", Info().source));
|
||||||
return false;
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ReadHeader(false) == false )
|
if ( ReadHeader(false) == false )
|
||||||
{
|
{
|
||||||
return false;
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -334,7 +368,9 @@ bool Ascii::DoUpdate()
|
||||||
delete fields[i];
|
delete fields[i];
|
||||||
|
|
||||||
delete [] fields;
|
delete [] fields;
|
||||||
return false;
|
|
||||||
|
is_failed = true;
|
||||||
|
return continue_on_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value* val = formatter->ParseValue(stringfields[(*fit).position], (*fit).name, (*fit).type, (*fit).subtype);
|
Value* val = formatter->ParseValue(stringfields[(*fit).position], (*fit).name, (*fit).type, (*fit).subtype);
|
||||||
|
@ -390,6 +426,15 @@ bool Ascii::DoUpdate()
|
||||||
|
|
||||||
bool Ascii::DoHeartbeat(double network_time, double current_time)
|
bool Ascii::DoHeartbeat(double network_time, double current_time)
|
||||||
{
|
{
|
||||||
|
printf("heartbeat\n");
|
||||||
|
is_failed = false;
|
||||||
|
|
||||||
|
if ( ! file.is_open() )
|
||||||
|
OpenFile();
|
||||||
|
|
||||||
|
//if ( is_failed )
|
||||||
|
// return continue_on_failure;
|
||||||
|
|
||||||
switch ( Info().mode )
|
switch ( Info().mode )
|
||||||
{
|
{
|
||||||
case MODE_MANUAL:
|
case MODE_MANUAL:
|
||||||
|
|
|
@ -55,7 +55,9 @@ protected:
|
||||||
private:
|
private:
|
||||||
bool ReadHeader(bool useCached);
|
bool ReadHeader(bool useCached);
|
||||||
bool GetLine(string& str);
|
bool GetLine(string& str);
|
||||||
|
bool OpenFile();
|
||||||
|
|
||||||
|
string filename;
|
||||||
ifstream file;
|
ifstream file;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
|
|
||||||
|
@ -71,6 +73,9 @@ private:
|
||||||
string empty_field;
|
string empty_field;
|
||||||
string unset_field;
|
string unset_field;
|
||||||
|
|
||||||
|
bool continue_on_failure;
|
||||||
|
bool is_failed;
|
||||||
|
|
||||||
std::unique_ptr<threading::formatter::Formatter> formatter;
|
std::unique_ptr<threading::formatter::Formatter> formatter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue