mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Allow File analyzers to direcly pass mime type.
This makes it much easier for protocols where the mime type is known in advance like, for example, TLS. We now do no longer have to perform deep script-level magic.
This commit is contained in:
parent
1b19ab78b6
commit
9fd7816501
12 changed files with 89 additions and 26 deletions
|
@ -55,6 +55,7 @@ int File::bof_buffer_size_idx = -1;
|
|||
int File::bof_buffer_idx = -1;
|
||||
int File::meta_mime_type_idx = -1;
|
||||
int File::meta_mime_types_idx = -1;
|
||||
int File::meta_inferred_idx = -1;
|
||||
|
||||
void File::StaticInit()
|
||||
{
|
||||
|
@ -76,6 +77,7 @@ void File::StaticInit()
|
|||
bof_buffer_idx = Idx("bof_buffer", fa_file_type);
|
||||
meta_mime_type_idx = Idx("mime_type", fa_metadata_type);
|
||||
meta_mime_types_idx = Idx("mime_types", fa_metadata_type);
|
||||
meta_inferred_idx = Idx("inferred", fa_metadata_type);
|
||||
}
|
||||
|
||||
File::File(const string& file_id, const string& source_name, Connection* conn,
|
||||
|
@ -290,6 +292,27 @@ void File::SetReassemblyBuffer(uint64 max)
|
|||
reassembly_max_buffer = max;
|
||||
}
|
||||
|
||||
bool File::SetMime(const string& mime_type)
|
||||
{
|
||||
if ( mime_type.empty() || bof_buffer.size != 0 )
|
||||
return false;
|
||||
|
||||
did_metadata_inference = true;
|
||||
bof_buffer.full = true;
|
||||
|
||||
if ( ! FileEventAvailable(file_sniff) )
|
||||
return false;
|
||||
|
||||
val_list* vl = new val_list();
|
||||
vl->append(val->Ref());
|
||||
RecordVal* meta = new RecordVal(fa_metadata_type);
|
||||
vl->append(meta);
|
||||
meta->Assign(meta_mime_type_idx, new StringVal(mime_type));
|
||||
meta->Assign(meta_inferred_idx, new Val(0, TYPE_BOOL));
|
||||
FileEvent(file_sniff, vl);
|
||||
return true;
|
||||
}
|
||||
|
||||
void File::InferMetadata()
|
||||
{
|
||||
did_metadata_inference = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue