mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
compiles. sill doesn't do much.
This commit is contained in:
parent
9c8b0dec3b
commit
3654060246
9 changed files with 117 additions and 29 deletions
|
@ -2,9 +2,11 @@
|
||||||
module Input;
|
module Input;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
type Event: record {
|
type ReaderDescription: record {
|
||||||
name: string;
|
source: string;
|
||||||
columns: any;
|
idx: any;
|
||||||
|
val: any;
|
||||||
|
destination: any;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,14 @@ InputMgr::InputMgr()
|
||||||
|
|
||||||
|
|
||||||
// create a new input reader object to be used at whomevers leisure lateron.
|
// create a new input reader object to be used at whomevers leisure lateron.
|
||||||
InputReader* InputMgr::CreateReader(EnumVal* reader, string source, RecordVal* event)
|
InputReader* InputMgr::CreateReader(EnumVal* reader, RecordVal* description)
|
||||||
{
|
{
|
||||||
InputReaderDefinition* ir = input_readers;
|
InputReaderDefinition* ir = input_readers;
|
||||||
|
|
||||||
RecordType* rtype = InputReaderDefinition->Type()->AsRecordType();
|
RecordType* rtype = description->Type()->AsRecordType();
|
||||||
if ( ! same_type(rtype, BifType::Record::Input::Event, 0) )
|
if ( ! same_type(rtype, BifType::Record::Input::ReaderDescription, 0) )
|
||||||
{
|
{
|
||||||
reporter->Error("eventDescription argument not of right type");
|
reporter->Error("readerDescription argument not of right type");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,11 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source, RecordVal* e
|
||||||
InputReader* reader_obj = (*ir->factory)();
|
InputReader* reader_obj = (*ir->factory)();
|
||||||
assert(reader_obj);
|
assert(reader_obj);
|
||||||
|
|
||||||
reader_obj->Init(source, eventName);
|
// get the source...
|
||||||
|
const BroString* bsource = description->Lookup(rtype->FieldOffset("source"))->AsString();
|
||||||
|
string source((const char*) bsource->Bytes(), bsource->Len());
|
||||||
|
|
||||||
|
reader_obj->Init(source, 0, NULL);
|
||||||
|
|
||||||
return reader_obj;
|
return reader_obj;
|
||||||
|
|
||||||
|
@ -100,6 +104,27 @@ void InputMgr::Error(InputReader* reader, const char* msg)
|
||||||
reader->Source().c_str(), msg));
|
reader->Source().c_str(), msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO:
|
||||||
|
|
||||||
|
void InputMgr::SendEvent(string name) {
|
||||||
|
//EventHandler* handler = event_registry->Lookup(eventName.c_str());
|
||||||
|
|
||||||
|
//if ( handler == 0 ) {
|
||||||
|
// reporter->Error("Event %s not found", eventName.c_str());
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//val_list* vl = new val_list;
|
||||||
|
//vl->append(new Val(12, TYPE_COUNT));
|
||||||
|
|
||||||
|
//mgr.Dispatch(new Event(handler, vl));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,16 @@
|
||||||
#include "Val.h"
|
#include "Val.h"
|
||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
#include "RemoteSerializer.h"
|
#include "RemoteSerializer.h"
|
||||||
|
#include "LogMgr.h" // for the LogVal and LogType data types
|
||||||
|
|
||||||
class InputReader;
|
class InputReader;
|
||||||
|
|
||||||
|
|
||||||
class InputMgr {
|
class InputMgr {
|
||||||
public:
|
public:
|
||||||
InputMgr();
|
InputMgr();
|
||||||
|
|
||||||
InputReader* CreateReader(EnumVal* reader, string source, RecordVal* event);
|
InputReader* CreateReader(EnumVal* reader, RecordVal* description);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class InputReader;
|
friend class InputReader;
|
||||||
|
@ -24,6 +26,10 @@ 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);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// required functionality
|
||||||
|
// InputValsToRecord to convert received inputvals back to bro records / tables / whatever
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern InputMgr* input_mgr;
|
extern InputMgr* input_mgr;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
InputReader::InputReader()
|
InputReader::InputReader()
|
||||||
{
|
{
|
||||||
|
disabled = true; // disabled will be set correcty in init.
|
||||||
}
|
}
|
||||||
|
|
||||||
InputReader::~InputReader()
|
InputReader::~InputReader()
|
||||||
|
@ -18,17 +18,18 @@ void InputReader::Error(const char *msg)
|
||||||
input_mgr->Error(this, msg);
|
input_mgr->Error(this, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputReader::Init(string source, string eventName) {
|
bool InputReader::Init(string arg_source, int arg_num_fields,
|
||||||
//EventHandler* handler = event_registry->Lookup(eventName.c_str());
|
const LogField* const * arg_fields)
|
||||||
|
{
|
||||||
|
source = arg_source;
|
||||||
|
num_fields = arg_num_fields;
|
||||||
|
fields = arg_fields;
|
||||||
|
|
||||||
//if ( handler == 0 ) {
|
// disable if DoInit returns error.
|
||||||
// reporter->Error("Event %s not found", eventName.c_str());
|
disabled = !DoInit(arg_source, arg_num_fields, arg_fields);
|
||||||
// return false;
|
return !disabled;
|
||||||
//}
|
}
|
||||||
|
|
||||||
//val_list* vl = new val_list;
|
void InputReader::Finish() {
|
||||||
//vl->append(new Val(12, TYPE_COUNT));
|
DoFinish();
|
||||||
|
|
||||||
//mgr.Dispatch(new Event(handler, vl));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
|
@ -8,16 +8,22 @@
|
||||||
|
|
||||||
#include "InputMgr.h"
|
#include "InputMgr.h"
|
||||||
#include "BroString.h"
|
#include "BroString.h"
|
||||||
|
#include "LogMgr.h"
|
||||||
|
|
||||||
class InputReader {
|
class InputReader {
|
||||||
public:
|
public:
|
||||||
InputReader();
|
InputReader();
|
||||||
virtual ~InputReader();
|
virtual ~InputReader();
|
||||||
|
|
||||||
bool Init(string source, string eventName);
|
bool Init(string arg_source, int num_fields, const LogField* const* fields);
|
||||||
|
|
||||||
|
void Finish();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Methods that have to be overwritten by the individual readers
|
// Methods that have to be overwritten by the individual readers
|
||||||
|
virtual bool DoInit(string arg_source, int num_fields, const LogField* const * fields) = 0;
|
||||||
|
|
||||||
|
virtual void DoFinish() = 0;
|
||||||
|
|
||||||
// Reports an error to the user.
|
// Reports an error to the user.
|
||||||
void Error(const char *msg);
|
void Error(const char *msg);
|
||||||
|
@ -29,6 +35,8 @@ private:
|
||||||
friend class InputMgr;
|
friend class InputMgr;
|
||||||
|
|
||||||
string source;
|
string source;
|
||||||
|
int num_fields;
|
||||||
|
const LogField* const * fields;
|
||||||
|
|
||||||
// When an error occurs, this method is called to set a flag marking the
|
// When an error occurs, this method is called to set a flag marking the
|
||||||
// writer as disabled.
|
// writer as disabled.
|
||||||
|
|
|
@ -2,11 +2,47 @@
|
||||||
#include "InputReaderAscii.h"
|
#include "InputReaderAscii.h"
|
||||||
#include "DebugLogger.h"
|
#include "DebugLogger.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
InputReaderAscii::InputReaderAscii()
|
InputReaderAscii::InputReaderAscii()
|
||||||
{
|
{
|
||||||
DBG_LOG(DBG_LOGGING, "input reader initialized");
|
//DBG_LOG(DBG_LOGGING, "input reader initialized");
|
||||||
|
file = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputReaderAscii::~InputReaderAscii()
|
InputReaderAscii::~InputReaderAscii()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputReaderAscii::DoFinish()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InputReaderAscii::DoInit(string path, int num_fields,
|
||||||
|
const LogField* const * fields)
|
||||||
|
{
|
||||||
|
fname = path;
|
||||||
|
|
||||||
|
file = new ifstream(path.c_str());
|
||||||
|
if ( !file->is_open() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to read the header line...
|
||||||
|
string line;
|
||||||
|
if ( !getline(*file, line) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// split on tabs...
|
||||||
|
istringstream ss(line);
|
||||||
|
while ( ss ) {
|
||||||
|
string s;
|
||||||
|
if ( !getline(ss, s, '\t'))
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -3,6 +3,9 @@
|
||||||
#define INPUTREADERASCII_H
|
#define INPUTREADERASCII_H
|
||||||
|
|
||||||
#include "InputReader.h"
|
#include "InputReader.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
class InputReaderAscii : public InputReader {
|
class InputReaderAscii : public InputReader {
|
||||||
public:
|
public:
|
||||||
|
@ -13,7 +16,14 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
virtual bool DoInit(string path, int num_fields,
|
||||||
|
const LogField* const * fields);
|
||||||
|
virtual void DoFinish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
ifstream* file;
|
||||||
|
string fname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -475,7 +475,7 @@ void LogMgr::RemoveDisabledWriters(Stream* stream)
|
||||||
stream->writers.erase(*j);
|
stream->writers.erase(*j);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogMgr::(EnumVal* id, RecordVal* sval)
|
bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
|
||||||
{
|
{
|
||||||
RecordType* rtype = sval->Type()->AsRecordType();
|
RecordType* rtype = sval->Type()->AsRecordType();
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,11 @@ module Input;
|
||||||
#include "NetVar.h"
|
#include "NetVar.h"
|
||||||
%%}
|
%%}
|
||||||
|
|
||||||
type Event: record;
|
type ReaderDescription: record;
|
||||||
|
|
||||||
function Input::__create_reader%(reader: Input::Reader, source: string, eventDescription: Input::Event%) : bool
|
function Input::__create_reader%(reader: Input::Reader, description: Input::ReaderDescription%) : bool
|
||||||
%{
|
%{
|
||||||
InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), source->AsString()->CheckString(), eventDescription->AsRecordVal());
|
InputReader *the_reader = input_mgr->CreateReader(reader->AsEnumVal(), description->AsRecordVal());
|
||||||
return new Val( the_reader != 0, TYPE_BOOL );
|
return new Val( the_reader != 0, TYPE_BOOL );
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue