File: SQLite.h

package info (click to toggle)
bro 2.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 79,416 kB
  • sloc: ansic: 129,203; cpp: 96,492; yacc: 2,528; lex: 1,819; sh: 795; python: 700; makefile: 136
file content (59 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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 "bro-config.h"

#include "logging/WriterBackend.h"
#include "threading/formatters/Ascii.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(const WriterInfo& info, int arg_num_fields,
			    const threading::Field* const* arg_fields);
	virtual bool DoWrite(int num_fields, const threading::Field* const* fields,
			     threading::Value** vals);
	virtual bool DoSetBuf(bool enabled) { return true; }
	virtual bool DoRotate(const char* rotated_path, double open,
			      double close, bool terminating);
	virtual bool DoFlush(double network_time)	{ return true; }
	virtual bool DoFinish(double network_time)	{ return true; }
	virtual bool DoHeartbeat(double network_time, double current_time)	{ return true; }

private:
	bool checkError(int code);

	int AddParams(threading::Value* val, int pos);
	string GetTableType(int, int);

	const threading::Field* const * fields; // raw mapping
	unsigned int num_fields;

	sqlite3 *db;
	sqlite3_stmt *st;

	string set_separator;
	string unset_field;
	string empty_field;

	threading::formatter::Ascii* io;
};

}
}

#endif /* LOGGING_WRITER_SQLITE_H */