mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
very basic input to event working...
This commit is contained in:
parent
d7a3b85fcd
commit
5b0c307f87
5 changed files with 42 additions and 8 deletions
|
@ -5,8 +5,8 @@ export {
|
||||||
type ReaderDescription: record {
|
type ReaderDescription: record {
|
||||||
source: string;
|
source: string;
|
||||||
idx: any;
|
idx: any;
|
||||||
val: any;
|
val: any &optional;
|
||||||
destination: any;
|
destination: any &optional;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,21 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, RecordVal* description)
|
||||||
const BroString* bsource = description->Lookup(rtype->FieldOffset("source"))->AsString();
|
const BroString* bsource = description->Lookup(rtype->FieldOffset("source"))->AsString();
|
||||||
string source((const char*) bsource->Bytes(), bsource->Len());
|
string source((const char*) bsource->Bytes(), bsource->Len());
|
||||||
|
|
||||||
reader_obj->Init(source, 0, NULL);
|
RecordType *idx = description->Lookup(rtype->FieldOffset("idx"))->AsType()->AsTypeType()->Type()->AsRecordType();
|
||||||
|
|
||||||
|
LogField** fields = new LogField*[idx->NumFields()];
|
||||||
|
for ( int i = 0; i < idx->NumFields(); i++ )
|
||||||
|
{
|
||||||
|
// FIXME: do type checking...
|
||||||
|
LogField* field = new LogField();
|
||||||
|
field->name = idx->FieldName(i);
|
||||||
|
field->type = idx->FieldType(i)->Tag();
|
||||||
|
fields[i] = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
reader_obj->Init(source, idx->NumFields(), fields);
|
||||||
|
reader_obj->Update();
|
||||||
|
|
||||||
return reader_obj;
|
return reader_obj;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
InputReader::InputReader()
|
InputReader::InputReader()
|
||||||
{
|
{
|
||||||
|
buf = 0;
|
||||||
|
buf_len = 1024;
|
||||||
disabled = true; // disabled will be set correcty in init.
|
disabled = true; // disabled will be set correcty in init.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +20,11 @@ void InputReader::Error(const char *msg)
|
||||||
input_mgr->Error(this, msg);
|
input_mgr->Error(this, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputReader::Error(const string &msg)
|
||||||
|
{
|
||||||
|
input_mgr->Error(this, msg.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
bool InputReader::Init(string arg_source, int arg_num_fields,
|
bool InputReader::Init(string arg_source, int arg_num_fields,
|
||||||
const LogField* const * arg_fields)
|
const LogField* const * arg_fields)
|
||||||
{
|
{
|
||||||
|
@ -38,6 +45,10 @@ bool InputReader::Update() {
|
||||||
return DoUpdate();
|
return DoUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputReader::SendEvent(const string& name, const int num_vals, const LogVal* const *vals) {
|
||||||
|
input_mgr->SendEvent(name, num_vals, vals);
|
||||||
|
}
|
||||||
|
|
||||||
// stolen from logwriter
|
// stolen from logwriter
|
||||||
const char* InputReader::Fmt(const char* format, ...)
|
const char* InputReader::Fmt(const char* format, ...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ protected:
|
||||||
virtual bool DoUpdate() = 0;
|
virtual bool DoUpdate() = 0;
|
||||||
|
|
||||||
// Reports an error to the user.
|
// Reports an error to the user.
|
||||||
|
void Error(const string &msg);
|
||||||
void Error(const char *msg);
|
void Error(const char *msg);
|
||||||
|
|
||||||
// The following methods return the information as passed to Init().
|
// The following methods return the information as passed to Init().
|
||||||
|
@ -39,6 +40,8 @@ protected:
|
||||||
// A thread-safe version of fmt(). (stolen from logwriter)
|
// A thread-safe version of fmt(). (stolen from logwriter)
|
||||||
const char* Fmt(const char* format, ...);
|
const char* Fmt(const char* format, ...);
|
||||||
|
|
||||||
|
void SendEvent(const string& name, const int num_vals, const LogVal* const *vals);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class InputMgr;
|
friend class InputMgr;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ bool InputReaderAscii::DoInit(string path, int num_fields, const LogField* const
|
||||||
|
|
||||||
file = new ifstream(path.c_str());
|
file = new ifstream(path.c_str());
|
||||||
if ( !file->is_open() ) {
|
if ( !file->is_open() ) {
|
||||||
Error(Fmt("cannot open %s", path.c_str()));
|
Error(Fmt("cannot open %s", fname.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
istringstream splitstream(line);
|
istringstream splitstream(line);
|
||||||
string s;
|
string s;
|
||||||
|
|
||||||
LogVal fields[num_fields];
|
LogVal** fields = new LogVal*[num_fields];
|
||||||
|
|
||||||
unsigned int currTab = 0;
|
unsigned int currTab = 0;
|
||||||
unsigned int currField = 0;
|
unsigned int currField = 0;
|
||||||
|
@ -136,11 +136,12 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogVal val(currMapping.type, true);
|
LogVal* val = new LogVal(currMapping.type, true);
|
||||||
|
|
||||||
switch ( currMapping.type ) {
|
switch ( currMapping.type ) {
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
val.val.string_val = new string(s);
|
val->val.string_val = new string(s);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Error(Fmt("unsupported field format %d for %s", currMapping.type,
|
Error(Fmt("unsupported field format %d for %s", currMapping.type,
|
||||||
|
@ -148,6 +149,8 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fields[currField] = val;
|
||||||
|
|
||||||
currField++;
|
currField++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +160,9 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, now we have built our line. send it back to... whomever.
|
// ok, now we have built our line. send it back to... whomever.
|
||||||
|
// for testing purposes: fixed event.
|
||||||
|
|
||||||
|
SendEvent("inputEvent", num_fields, fields);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue