From edacb6372310667af624ba8c9273aca9e02945f7 Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org" Date: Thu, 15 Dec 2005 12:37:58 +0000 Subject: don't "#include" a .c file but rather compile db.c on it's own --- util/db.c | 68 +++++++++++++-------------------------------------------------- 1 file changed, 14 insertions(+), 54 deletions(-) (limited to 'util/db.c') diff --git a/util/db.c b/util/db.c index 2395712..c91c7dc 100644 --- a/util/db.c +++ b/util/db.c @@ -24,60 +24,22 @@ * $Id: ulogd_output_MYSQL.c 6304 2005-12-08 09:43:19Z /C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=laforge/emailAddress=laforge@netfilter.org $ */ -/* generic db layer */ +#include +#include +#include +#include +#include -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); - char *(*strerror)(struct ulogd_pluginstance *upi); -}; - -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 DB_CES \ - { \ - .key = "table", \ - .type = CONFIG_TYPE_STRING, \ - .options = CONFIG_OPT_MANDATORY, \ - }, \ - { \ - .key = "reconnect", \ - .type = CONFIG_TYPE_INT, \ - }, \ - { \ - .key = "ip_as_string", \ - .type = CONFIG_TYPE_INT, \ - }, \ - { \ - .key = "connect_timeout", \ - .type = CONFIG_TYPE_INT, \ - } +#include +#include -#define DB_CE_NUM 4 -#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]) +/* generic db layer */ static int __interp_db(struct ulogd_pluginstance *upi); /* this is a wrapper that just calls the current real * interp function */ -static int interp_db(struct ulogd_pluginstance *upi) +int ulogd_db_interp(struct ulogd_pluginstance *upi) { struct db_instance *dbi = (struct db_instance *) &upi->private; return dbi->interp(upi); @@ -150,7 +112,7 @@ static int sql_createstmt(struct ulogd_pluginstance *upi) return 0; } -static int configure_db(struct ulogd_pluginstance *upi, +int ulogd_db_configure(struct ulogd_pluginstance *upi, struct ulogd_pluginstance_stack *stack) { struct db_instance *di = (struct db_instance *) upi->private; @@ -185,7 +147,7 @@ static int configure_db(struct ulogd_pluginstance *upi, return ret; } -static int start_db(struct ulogd_pluginstance *upi) +int ulogd_db_start(struct ulogd_pluginstance *upi) { struct db_instance *di = (struct db_instance *) upi->private; int ret; @@ -203,7 +165,7 @@ static int start_db(struct ulogd_pluginstance *upi) return ret; } -static int stop_db(struct ulogd_pluginstance *upi) +int ulogd_db_stop(struct ulogd_pluginstance *upi) { struct db_instance *di = (struct db_instance *) upi->private; ulogd_log(ULOGD_NOTICE, "stopping\n"); @@ -251,7 +213,7 @@ static int _init_db(struct ulogd_pluginstance *upi) if (open_db(upi)) { ulogd_log(ULOGD_ERROR, "can't establish database connection\n"); - return init_reconnect(upi); + return _init_reconnect(upi); } /* enable 'real' logging */ @@ -356,7 +318,6 @@ static int __interp_db(struct ulogd_pluginstance *upi) di->stmt_ins = di->stmt + strlen(di->stmt); } *(di->stmt_ins - 1) = ')'; - DEBUGP("stmt=#%s#\n", di->stmt); /* now we have created our statement, insert it */ @@ -369,8 +330,7 @@ static int __interp_db(struct ulogd_pluginstance *upi) return 0; } -static void signal_db(struct ulogd_pluginstance *upi, - int signal) +void ulogd_db_signal(struct ulogd_pluginstance *upi, int signal) { switch (signal) { case SIGHUP: -- cgit v1.2.3