summaryrefslogtreecommitdiffstats
path: root/include/ulogd/db.h
blob: 62819f2fe8ef0aa1f40f71ea3c007be2f3eb98ff (plain)
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
60
61
62
63
64
65
66
67
68
#ifndef _ULOGD_DB_H
#define _ULOGD_DB_H

#include <ulogd/ulogd.h>

struct db_driver {
	int (*get_columns)(struct ulogd_pluginstance *upi);
	int (*open_db)(struct ulogd_pluginstance *upi);
	int (*close_db)(struct ulogd_pluginstance *upi);
	int (*escape_string)(struct ulogd_pluginstance *upi,
			     char *dst, const char *src, unsigned int len);
	int (*execute)(struct ulogd_pluginstance *upi,
			const char *stmt, unsigned int len);
};

struct db_instance {
	char *stmt; /* buffer for our insert statement */
	char *stmt_val; /* pointer to the beginning of the "VALUES" part */
	char *stmt_ins; /* pointer to current inser position in statement */
	char *schema;
	time_t reconnect;
	int (*interp)(struct ulogd_pluginstance *upi);
	struct db_driver *driver;
};
#define TIME_ERR		((time_t)-1)	/* Be paranoid */
#define RECONNECT_DEFAULT	2

#define DB_CES							\
		{						\
			.key = "table",				\
			.type = CONFIG_TYPE_STRING,		\
			.options = CONFIG_OPT_MANDATORY,	\
		},						\
		{						\
			.key = "reconnect",			\
			.type = CONFIG_TYPE_INT,		\
			.u.value = RECONNECT_DEFAULT,		\
		},						\
		{						\
			.key = "ip_as_string",			\
			.type = CONFIG_TYPE_INT,		\
		},						\
		{						\
			.key = "connect_timeout",		\
			.type = CONFIG_TYPE_INT,		\
		},						\
		{						\
			.key = "procedure",			\
			.type = CONFIG_TYPE_STRING,		\
			.options = CONFIG_OPT_MANDATORY,	\
		}

#define DB_CE_NUM	5
#define table_ce(x)	(x->ces[0])
#define reconnect_ce(x)	(x->ces[1])
#define asstring_ce(x)	(x->ces[2])
#define timeout_ce(x)	(x->ces[3])
#define procedure_ce(x)	(x->ces[4])

void ulogd_db_signal(struct ulogd_pluginstance *upi, int signal);
int ulogd_db_start(struct ulogd_pluginstance *upi);
int ulogd_db_stop(struct ulogd_pluginstance *upi);
int ulogd_db_interp(struct ulogd_pluginstance *upi);
int ulogd_db_configure(struct ulogd_pluginstance *upi,
			struct ulogd_pluginstance_stack *stack);


#endif