mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
introduce reader-info struct analogous to writer-info.
All tests still pass.
This commit is contained in:
parent
f820ee9f5c
commit
3559a39d59
11 changed files with 162 additions and 70 deletions
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "threading/SerialTypes.h"
|
||||
#include "threading/MsgThread.h"
|
||||
class RemoteSerializer;
|
||||
|
||||
|
||||
namespace input {
|
||||
|
||||
|
@ -65,6 +67,35 @@ public:
|
|||
*/
|
||||
virtual ~ReaderBackend();
|
||||
|
||||
/**
|
||||
* A struct passing information to the reader at initialization time.
|
||||
*/
|
||||
struct ReaderInfo
|
||||
{
|
||||
typedef std::map<string, string> config_map;
|
||||
|
||||
/**
|
||||
* A string left to the interpretation of the reader
|
||||
* implementation; it corresponds to the value configured on
|
||||
* the script-level for the logging filter.
|
||||
*/
|
||||
string source;
|
||||
|
||||
/**
|
||||
* A map of key/value pairs corresponding to the relevant
|
||||
* filter's "config" table.
|
||||
*/
|
||||
config_map config;
|
||||
|
||||
private:
|
||||
friend class ::RemoteSerializer;
|
||||
|
||||
// Note, these need to be adapted when changing the struct's
|
||||
// fields. They serialize/deserialize the struct.
|
||||
bool Read(SerializationFormat* fmt);
|
||||
bool Write(SerializationFormat* fmt) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* One-time initialization of the reader to define the input source.
|
||||
*
|
||||
|
@ -84,7 +115,7 @@ public:
|
|||
*
|
||||
* @return False if an error occured.
|
||||
*/
|
||||
bool Init(string source, ReaderMode mode, int num_fields, const threading::Field* const* fields, std::map<string, string> config);
|
||||
bool Init(const ReaderInfo& info, ReaderMode mode, int num_fields, const threading::Field* const* fields);
|
||||
|
||||
/**
|
||||
* Finishes reading from this input stream in a regular fashion. Must
|
||||
|
@ -112,6 +143,22 @@ public:
|
|||
*/
|
||||
void DisableFrontend();
|
||||
|
||||
/**
|
||||
* Returns the log fields as passed into the constructor.
|
||||
*/
|
||||
const threading::Field* const * Fields() const { return fields; }
|
||||
|
||||
/**
|
||||
* Returns the additional reader information into the constructor.
|
||||
*/
|
||||
const ReaderInfo& Info() const { return info; }
|
||||
|
||||
/**
|
||||
* Returns the number of log fields as passed into the constructor.
|
||||
*/
|
||||
int NumFields() const { return num_fields; }
|
||||
|
||||
|
||||
protected:
|
||||
// Methods that have to be overwritten by the individual readers
|
||||
|
||||
|
@ -133,7 +180,7 @@ protected:
|
|||
* provides accessor methods to get them later, and they are passed
|
||||
* in here only for convinience.
|
||||
*/
|
||||
virtual bool DoInit(string path, ReaderMode mode, int arg_num_fields, const threading::Field* const* fields, const std::map<string, string> config) = 0;
|
||||
virtual bool DoInit(const ReaderInfo& info, ReaderMode mode, int arg_num_fields, const threading::Field* const* fields) = 0;
|
||||
|
||||
/**
|
||||
* Reader-specific method implementing input finalization at
|
||||
|
@ -162,26 +209,11 @@ protected:
|
|||
*/
|
||||
virtual bool DoUpdate() = 0;
|
||||
|
||||
/**
|
||||
* Returns the input source as passed into Init()/.
|
||||
*/
|
||||
const string Source() const { return source; }
|
||||
|
||||
/**
|
||||
* Returns the reader mode as passed into Init().
|
||||
*/
|
||||
const ReaderMode Mode() const { return mode; }
|
||||
|
||||
/**
|
||||
* Returns the number of log fields as passed into Init().
|
||||
*/
|
||||
unsigned int NumFields() const { return num_fields; }
|
||||
|
||||
/**
|
||||
* Returns the log fields as passed into Init().
|
||||
*/
|
||||
const threading::Field* const * Fields() const { return fields; }
|
||||
|
||||
/**
|
||||
* Method allowing a reader to send a specified Bro event. Vals must
|
||||
* match the values expected by the bro event.
|
||||
|
@ -282,7 +314,7 @@ private:
|
|||
// from this class, it's running in a different thread!
|
||||
ReaderFrontend* frontend;
|
||||
|
||||
string source;
|
||||
ReaderInfo info;
|
||||
ReaderMode mode;
|
||||
unsigned int num_fields;
|
||||
const threading::Field* const * fields; // raw mapping
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue