mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
yay, basic table assignment.
This commit is contained in:
parent
5b0c307f87
commit
b245d4168a
6 changed files with 87 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 &optional;
|
val: any;
|
||||||
destination: any &optional;
|
destination: any;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,16 @@
|
||||||
|
|
||||||
#include "InputReaderAscii.h"
|
#include "InputReaderAscii.h"
|
||||||
|
|
||||||
|
struct InputMgr::ReaderInfo {
|
||||||
|
EnumVal* id;
|
||||||
|
EnumVal* type;
|
||||||
|
InputReader* reader;
|
||||||
|
unsigned int num_idx_fields;
|
||||||
|
unsigned int num_val_fields;
|
||||||
|
|
||||||
|
TableVal* tab;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
struct InputReaderDefinition {
|
struct InputReaderDefinition {
|
||||||
bro_int_t type; // the type
|
bro_int_t type; // the type
|
||||||
|
@ -30,7 +40,7 @@ InputReaderDefinition input_readers[] = {
|
||||||
|
|
||||||
InputMgr::InputMgr()
|
InputMgr::InputMgr()
|
||||||
{
|
{
|
||||||
DBG_LOG(DBG_LOGGING, "this has to happen");
|
//DBG_LOG(DBG_LOGGING, "this has to happen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,8 +103,10 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, RecordVal* description)
|
||||||
string source((const char*) bsource->Bytes(), bsource->Len());
|
string source((const char*) bsource->Bytes(), bsource->Len());
|
||||||
|
|
||||||
RecordType *idx = description->Lookup(rtype->FieldOffset("idx"))->AsType()->AsTypeType()->Type()->AsRecordType();
|
RecordType *idx = description->Lookup(rtype->FieldOffset("idx"))->AsType()->AsTypeType()->Type()->AsRecordType();
|
||||||
|
RecordType *val = description->Lookup(rtype->FieldOffset("val"))->AsType()->AsTypeType()->Type()->AsRecordType();
|
||||||
|
TableVal *dst = description->Lookup(rtype->FieldOffset("destination"))->AsTableVal();
|
||||||
|
|
||||||
LogField** fields = new LogField*[idx->NumFields()];
|
LogField** fields = new LogField*[idx->NumFields() + val->NumFields()];
|
||||||
for ( int i = 0; i < idx->NumFields(); i++ )
|
for ( int i = 0; i < idx->NumFields(); i++ )
|
||||||
{
|
{
|
||||||
// FIXME: do type checking...
|
// FIXME: do type checking...
|
||||||
|
@ -103,15 +115,43 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, RecordVal* description)
|
||||||
field->type = idx->FieldType(i)->Tag();
|
field->type = idx->FieldType(i)->Tag();
|
||||||
fields[i] = field;
|
fields[i] = field;
|
||||||
}
|
}
|
||||||
|
for ( int i = 0; i < val->NumFields(); i++ )
|
||||||
|
{
|
||||||
|
// FIXME: do type checking...
|
||||||
|
LogField* field = new LogField();
|
||||||
|
field->name = val->FieldName(i);
|
||||||
|
field->type = val->FieldType(i)->Tag();
|
||||||
|
fields[idx->NumFields() + i] = field;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReaderInfo* info = new ReaderInfo;
|
||||||
|
info->reader = reader_obj;
|
||||||
|
info->type = reader;
|
||||||
|
info->num_idx_fields = idx->NumFields();
|
||||||
|
info->num_val_fields = val->NumFields();
|
||||||
|
info->tab = dst;
|
||||||
|
readers.push_back(info);
|
||||||
|
|
||||||
|
|
||||||
reader_obj->Init(source, idx->NumFields(), fields);
|
reader_obj->Init(source, idx->NumFields() + val->NumFields(), fields);
|
||||||
reader_obj->Update();
|
reader_obj->Update();
|
||||||
|
|
||||||
return reader_obj;
|
return reader_obj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputMgr::Put(const InputReader* reader, const LogVal* const *vals) {
|
||||||
|
ReaderInfo *i = FindReader(reader);
|
||||||
|
if ( i == 0 ) {
|
||||||
|
reporter->InternalError("Unknown reader");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
i->tab->Assign(LogValToVal(vals[0]), LogValToVal(vals[1]));
|
||||||
|
reporter->Error("assigned");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InputMgr::Error(InputReader* reader, const char* msg)
|
void InputMgr::Error(InputReader* reader, const char* msg)
|
||||||
{
|
{
|
||||||
reporter->Error("error with input reader for %s: %s", reader->Source().c_str(), msg);
|
reporter->Error("error with input reader for %s: %s", reader->Source().c_str(), msg);
|
||||||
|
@ -172,4 +212,16 @@ Val* InputMgr::LogValToVal(const LogVal* val) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputMgr::ReaderInfo* InputMgr::FindReader(const InputReader* reader)
|
||||||
|
{
|
||||||
|
for ( vector<ReaderInfo *>::iterator s = readers.begin(); s != readers.end(); ++s )
|
||||||
|
{
|
||||||
|
if ( (*s)->reader == reader )
|
||||||
|
{
|
||||||
|
return *s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,13 +25,17 @@ protected:
|
||||||
// Reports an error for the given reader.
|
// Reports an error for the given reader.
|
||||||
void Error(InputReader* reader, const char* msg);
|
void Error(InputReader* reader, const char* msg);
|
||||||
|
|
||||||
|
void Put(const InputReader* reader, const LogVal* const *vals);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// required functionality
|
struct ReaderInfo;
|
||||||
// InputValsToRecord to convert received inputvals back to bro records / tables / whatever
|
|
||||||
Val* LogValToVal(const LogVal* val);
|
Val* LogValToVal(const LogVal* val);
|
||||||
|
|
||||||
void SendEvent(const string& name, const int num_vals, const LogVal* const *vals);
|
void SendEvent(const string& name, const int num_vals, const LogVal* const *vals);
|
||||||
|
ReaderInfo* FindReader(const InputReader* reader);
|
||||||
|
|
||||||
|
vector<ReaderInfo*> readers;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern InputMgr* input_mgr;
|
extern InputMgr* input_mgr;
|
||||||
|
|
|
@ -25,6 +25,11 @@ void InputReader::Error(const string &msg)
|
||||||
input_mgr->Error(this, msg.c_str());
|
input_mgr->Error(this, msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputReader::Put(const LogVal* const *val)
|
||||||
|
{
|
||||||
|
input_mgr->Put(this, val);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,6 +42,8 @@ protected:
|
||||||
|
|
||||||
void SendEvent(const string& name, const int num_vals, const LogVal* const *vals);
|
void SendEvent(const string& name, const int num_vals, const LogVal* const *vals);
|
||||||
|
|
||||||
|
void Put(const LogVal* const *val);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class InputMgr;
|
friend class InputMgr;
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,21 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
val->val.string_val = new string(s);
|
val->val.string_val = new string(s);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TYPE_BOOL:
|
||||||
|
case TYPE_INT:
|
||||||
|
val->val.int_val = atoi(s.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_DOUBLE:
|
||||||
|
case TYPE_TIME:
|
||||||
|
case TYPE_INTERVAL:
|
||||||
|
val->val.double_val = atof(s.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TYPE_COUNT:
|
||||||
|
val->val.uint_val = atoi(s.c_str());
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Error(Fmt("unsupported field format %d for %s", currMapping.type,
|
Error(Fmt("unsupported field format %d for %s", currMapping.type,
|
||||||
currMapping.name.c_str()));
|
currMapping.name.c_str()));
|
||||||
|
@ -163,6 +178,7 @@ bool InputReaderAscii::DoUpdate() {
|
||||||
// for testing purposes: fixed event.
|
// for testing purposes: fixed event.
|
||||||
|
|
||||||
SendEvent("inputEvent", num_fields, fields);
|
SendEvent("inputEvent", num_fields, fields);
|
||||||
|
Put(fields);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue