mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
basic sqlite writer seems to work.
does not support table and vector types because SQLite has no support for arrays. also does not support rotation, etc. Not really tested thoroughly - but starting bro with Log::default_writer=Log::WRITER_SQLITE yields a couple of sqlite files that seem to contain sensible stuff.
This commit is contained in:
parent
83dcbd4aa7
commit
6e0d15b55e
5 changed files with 395 additions and 0 deletions
53
src/logging/writers/SQLite.h
Normal file
53
src/logging/writers/SQLite.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
//
|
||||
// Log writer for SQLITE logs.
|
||||
|
||||
#ifndef LOGGING_WRITER_SQLITE_H
|
||||
#define LOGGING_WRITER_SQLITE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef USE_SQLITE
|
||||
|
||||
#include "../WriterBackend.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
namespace logging { namespace writer {
|
||||
|
||||
class SQLite : public WriterBackend {
|
||||
public:
|
||||
SQLite(WriterFrontend* frontend);
|
||||
~SQLite();
|
||||
|
||||
static WriterBackend* Instantiate(WriterFrontend* frontend)
|
||||
{ return new SQLite(frontend); }
|
||||
|
||||
protected:
|
||||
virtual bool DoInit(string path, int num_fields,
|
||||
const threading::Field* const* fields);
|
||||
virtual bool DoWrite(int num_fields, const threading::Field* const* fields,
|
||||
threading::Value** vals);
|
||||
virtual bool DoSetBuf(bool enabled);
|
||||
virtual bool DoRotate(string rotated_path, double open,
|
||||
double close, bool terminating);
|
||||
virtual bool DoFlush();
|
||||
virtual bool DoFinish();
|
||||
|
||||
private:
|
||||
bool checkError(int code);
|
||||
|
||||
int AddParams(threading::Value* val, int pos);
|
||||
string GetTableType(int, int);
|
||||
char* FS(const char* format, ...);
|
||||
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *st;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* USE_SQLITE */
|
||||
|
||||
#endif /* LOGGING_WRITER_SQLITE_H */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue