mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
FileAnalysis: minor code reorg/tweak of BOF buffering stuff.
This commit is contained in:
parent
720858fb36
commit
6cb58a5228
2 changed files with 14 additions and 19 deletions
|
@ -203,22 +203,11 @@ bool Info::BufferBOF(const u_char* data, uint64 len)
|
||||||
if ( bof_buffer.chunks.size() == 0 )
|
if ( bof_buffer.chunks.size() == 0 )
|
||||||
Manager::EvaluatePolicy(TRIGGER_BOF, this);
|
Manager::EvaluatePolicy(TRIGGER_BOF, this);
|
||||||
|
|
||||||
if ( ! data )
|
|
||||||
{
|
|
||||||
// A gap means we're done seeing as much as the start of the file
|
|
||||||
// as possible, replay anything that we have
|
|
||||||
bof_buffer.full = true;
|
|
||||||
ReplayBOF();
|
|
||||||
// TODO: libmagic stuff
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64 desired_size = LookupFieldDefaultCount(bof_buffer_size_idx);
|
uint64 desired_size = LookupFieldDefaultCount(bof_buffer_size_idx);
|
||||||
|
|
||||||
// If no buffer is desired or if the first chunk satisfies desired size,
|
/* Leaving out this optimization (I think) for now to keep things simpler.
|
||||||
// just do everything we need with the first chunk without copying.
|
// If first chunk satisfies desired size, do everything now without copying.
|
||||||
if ( desired_size == 0 ||
|
if ( bof_buffer.chunks.empty() && len >= desired_size )
|
||||||
(bof_buffer.chunks.empty() && len >= desired_size) )
|
|
||||||
{
|
{
|
||||||
bof_buffer.full = bof_buffer.replayed = true;
|
bof_buffer.full = bof_buffer.replayed = true;
|
||||||
val->Assign(bof_buffer_idx, new StringVal(new BroString(data, len, 0)));
|
val->Assign(bof_buffer_idx, new StringVal(new BroString(data, len, 0)));
|
||||||
|
@ -226,6 +215,7 @@ bool Info::BufferBOF(const u_char* data, uint64 len)
|
||||||
// TODO: libmagic stuff
|
// TODO: libmagic stuff
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
bof_buffer.chunks.push_back(new BroString(data, len, 0));
|
bof_buffer.chunks.push_back(new BroString(data, len, 0));
|
||||||
bof_buffer.size += len;
|
bof_buffer.size += len;
|
||||||
|
@ -233,7 +223,6 @@ bool Info::BufferBOF(const u_char* data, uint64 len)
|
||||||
if ( bof_buffer.size >= desired_size )
|
if ( bof_buffer.size >= desired_size )
|
||||||
{
|
{
|
||||||
bof_buffer.full = true;
|
bof_buffer.full = true;
|
||||||
// TODO: libmagic stuff
|
|
||||||
ReplayBOF();
|
ReplayBOF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +239,8 @@ void Info::ReplayBOF()
|
||||||
using BifEnum::FileAnalysis::TRIGGER_BOF_BUFFER;
|
using BifEnum::FileAnalysis::TRIGGER_BOF_BUFFER;
|
||||||
Manager::EvaluatePolicy(TRIGGER_BOF_BUFFER, this);
|
Manager::EvaluatePolicy(TRIGGER_BOF_BUFFER, this);
|
||||||
|
|
||||||
|
// TODO: libmagic stuff
|
||||||
|
|
||||||
for ( size_t i = 0; i < bof_buffer.chunks.size(); ++i )
|
for ( size_t i = 0; i < bof_buffer.chunks.size(); ++i )
|
||||||
DataIn(bof_buffer.chunks[i]->Bytes(), bof_buffer.chunks[i]->Len());
|
DataIn(bof_buffer.chunks[i]->Bytes(), bof_buffer.chunks[i]->Len());
|
||||||
}
|
}
|
||||||
|
@ -284,6 +275,7 @@ void Info::DataIn(const u_char* data, uint64 len, uint64 offset)
|
||||||
void Info::DataIn(const u_char* data, uint64 len)
|
void Info::DataIn(const u_char* data, uint64 len)
|
||||||
{
|
{
|
||||||
actions.FlushQueuedModifications();
|
actions.FlushQueuedModifications();
|
||||||
|
|
||||||
if ( BufferBOF(data, len) ) return;
|
if ( BufferBOF(data, len) ) return;
|
||||||
|
|
||||||
Action* act = 0;
|
Action* act = 0;
|
||||||
|
@ -312,9 +304,10 @@ void Info::EndOfFile()
|
||||||
{
|
{
|
||||||
if ( done ) return;
|
if ( done ) return;
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
actions.FlushQueuedModifications();
|
actions.FlushQueuedModifications();
|
||||||
|
|
||||||
// send along anything that's been buffered, but never flushed
|
// Send along anything that's been buffered, but never flushed.
|
||||||
ReplayBOF();
|
ReplayBOF();
|
||||||
|
|
||||||
Action* act = 0;
|
Action* act = 0;
|
||||||
|
@ -332,7 +325,10 @@ void Info::EndOfFile()
|
||||||
void Info::Gap(uint64 offset, uint64 len)
|
void Info::Gap(uint64 offset, uint64 len)
|
||||||
{
|
{
|
||||||
actions.FlushQueuedModifications();
|
actions.FlushQueuedModifications();
|
||||||
if ( BufferBOF(0, len) ) return;
|
|
||||||
|
// If we were buffering the beginning of the file, a gap means we've got
|
||||||
|
// as much contiguous stuff at the beginning as possible, so work with that.
|
||||||
|
ReplayBOF();
|
||||||
|
|
||||||
Action* act = 0;
|
Action* act = 0;
|
||||||
IterCookie* c = actions.InitForIteration();
|
IterCookie* c = actions.InitForIteration();
|
||||||
|
|
|
@ -143,8 +143,7 @@ protected:
|
||||||
double LookupFieldDefaultInterval(int idx) const;
|
double LookupFieldDefaultInterval(int idx) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffers incoming data at the beginning of a file. If \a data is a null
|
* Buffers incoming data at the beginning of a file.
|
||||||
* pointer, that signifies a gap and the buffering cannot continue.
|
|
||||||
* @return true if buffering is still required, else false
|
* @return true if buffering is still required, else false
|
||||||
*/
|
*/
|
||||||
bool BufferBOF(const u_char* data, uint64 len);
|
bool BufferBOF(const u_char* data, uint64 len);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue