mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +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;
|
||||
|
||||
export {
|
||||
type Event: record {
|
||||
name: string;
|
||||
columns: any;
|
||||
type ReaderDescription: record {
|
||||
source: string;
|
||||
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.
|
||||
InputReader* InputMgr::CreateReader(EnumVal* reader, string source, RecordVal* event)
|
||||
InputReader* InputMgr::CreateReader(EnumVal* reader, RecordVal* description)
|
||||
{
|
||||
InputReaderDefinition* ir = input_readers;
|
||||
|
||||
RecordType* rtype = InputReaderDefinition->Type()->AsRecordType();
|
||||
if ( ! same_type(rtype, BifType::Record::Input::Event, 0) )
|
||||
RecordType* rtype = description->Type()->AsRecordType();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,11 @@ InputReader* InputMgr::CreateReader(EnumVal* reader, string source, RecordVal* e
|
|||
InputReader* reader_obj = (*ir->factory)();
|
||||
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;
|
||||
|
||||
|
@ -100,6 +104,27 @@ void InputMgr::Error(InputReader* reader, const char* 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 "EventHandler.h"
|
||||
#include "RemoteSerializer.h"
|
||||
#include "LogMgr.h" // for the LogVal and LogType data types
|
||||
|
||||
class InputReader;
|
||||
|
||||
|
||||
class InputMgr {
|
||||
public:
|
||||
InputMgr();
|
||||
|
||||
InputReader* CreateReader(EnumVal* reader, string source, RecordVal* event);
|
||||
InputReader* CreateReader(EnumVal* reader, RecordVal* description);
|
||||
|
||||
protected:
|
||||
friend class InputReader;
|
||||
|
@ -24,6 +26,10 @@ protected:
|
|||
// Reports an error for the given reader.
|
||||
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;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
InputReader::InputReader()
|
||||
{
|
||||
|
||||
disabled = true; // disabled will be set correcty in init.
|
||||
}
|
||||
|
||||
InputReader::~InputReader()
|
||||
|
@ -18,17 +18,18 @@ void InputReader::Error(const char *msg)
|
|||
input_mgr->Error(this, msg);
|
||||
}
|
||||
|
||||
bool InputReader::Init(string source, string eventName) {
|
||||
//EventHandler* handler = event_registry->Lookup(eventName.c_str());
|
||||
bool InputReader::Init(string arg_source, int arg_num_fields,
|
||||
const LogField* const * arg_fields)
|
||||
{
|
||||
source = arg_source;
|
||||
num_fields = arg_num_fields;
|
||||
fields = arg_fields;
|
||||
|
||||
//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));
|
||||
return true;
|
||||
// disable if DoInit returns error.
|
||||
disabled = !DoInit(arg_source, arg_num_fields, arg_fields);
|
||||
return !disabled;
|
||||
}
|
||||
|
||||
void InputReader::Finish() {
|
||||
DoFinish();
|
||||
}
|
|
@ -8,16 +8,22 @@
|
|||
|
||||
#include "InputMgr.h"
|
||||
#include "BroString.h"
|
||||
#include "LogMgr.h"
|
||||
|
||||
class InputReader {
|
||||
public:
|
||||
InputReader();
|
||||
virtual ~InputReader();
|
||||
|
||||
bool Init(string source, string eventName);
|
||||
bool Init(string arg_source, int num_fields, const LogField* const* fields);
|
||||
|
||||
void Finish();
|
||||
|
||||
protected:
|
||||
// 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.
|
||||
void Error(const char *msg);
|
||||
|
@ -29,6 +35,8 @@ private:
|
|||
friend class InputMgr;
|
||||
|
||||
string source;
|
||||
int num_fields;
|
||||
const LogField* const * fields;
|
||||
|
||||
// When an error occurs, this method is called to set a flag marking the
|
||||
// writer as disabled.
|
||||
|
|
|
@ -2,11 +2,47 @@
|
|||
#include "InputReaderAscii.h"
|
||||
#include "DebugLogger.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
InputReaderAscii::InputReaderAscii()
|
||||
{
|
||||
DBG_LOG(DBG_LOGGING, "input reader initialized");
|
||||
//DBG_LOG(DBG_LOGGING, "input reader initialized");
|
||||
file = 0;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#include "InputReader.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class InputReaderAscii : public InputReader {
|
||||
public:
|
||||
|
@ -13,7 +16,14 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual bool DoInit(string path, int num_fields,
|
||||
const LogField* const * fields);
|
||||
virtual void DoFinish();
|
||||
|
||||
private:
|
||||
|
||||
ifstream* file;
|
||||
string fname;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -475,7 +475,7 @@ void LogMgr::RemoveDisabledWriters(Stream* stream)
|
|||
stream->writers.erase(*j);
|
||||
}
|
||||
|
||||
bool LogMgr::(EnumVal* id, RecordVal* sval)
|
||||
bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
|
||||
{
|
||||
RecordType* rtype = sval->Type()->AsRecordType();
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@ module Input;
|
|||
#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 );
|
||||
%}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue