[netfilter-cvslog] r6310 - branches/ulog/ulogd2/output/pgsql

laforge at netfilter.org laforge at netfilter.org
Fri Dec 9 14:33:58 CET 2005


Author: laforge at netfilter.org
Date: 2005-12-09 14:33:53 +0100 (Fri, 09 Dec 2005)
New Revision: 6310

Modified:
   branches/ulog/ulogd2/output/pgsql/Makefile.am
   branches/ulog/ulogd2/output/pgsql/ulogd_output_PGSQL.c
Log:
make pgsql plugin compile (untested)


Modified: branches/ulog/ulogd2/output/pgsql/Makefile.am
===================================================================
--- branches/ulog/ulogd2/output/pgsql/Makefile.am	2005-12-08 12:42:48 UTC (rev 6309)
+++ branches/ulog/ulogd2/output/pgsql/Makefile.am	2005-12-09 13:33:53 UTC (rev 6310)
@@ -1,5 +1,5 @@
 
-INCLUDES = $(all_includes) -I$(top_srcdir)/include
+INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(PGSQLINCLUDES)
 LIBS=$(PGSQL_LIBS)
 
 pkglib_LTLIBRARIES = ulogd_output_PGSQL.la

Modified: branches/ulog/ulogd2/output/pgsql/ulogd_output_PGSQL.c
===================================================================
--- branches/ulog/ulogd2/output/pgsql/ulogd_output_PGSQL.c	2005-12-08 12:42:48 UTC (rev 6309)
+++ branches/ulog/ulogd2/output/pgsql/ulogd_output_PGSQL.c	2005-12-09 13:33:53 UTC (rev 6310)
@@ -18,7 +18,7 @@
 #include <ulogd/ulogd.h>
 #include <ulogd/conffile.h>
 
-#include "../../utils/db.c"
+#include "../../util/db.c"
 
 #ifdef DEBUG_PGSQL
 #define DEBUGP(x, args...)	fprintf(stderr, x, ## args)
@@ -32,7 +32,7 @@
 	PGconn *dbh;
 	PGresult *pgres;
 	unsigned char pgsql_have_schemas;
-}
+};
 #define TIME_ERR	((time_t)-1)
 
 /* our configuration directives */
@@ -61,7 +61,6 @@
 			.options = CONFIG_OPT_NONE,
 		},
 		{
-			.next = &schema_ce,
 			.key = "port",
 			.type = CONFIG_TYPE_INT,
 		},
@@ -187,31 +186,34 @@
 #define PGSQL_HAVE_NAMESPACE_TEMPLATE "SELECT nspname FROM pg_namespace n WHERE n.nspname='%s'"
 
 /* Determine if server support schemas */
-static int pgsql_namespace(void)
+static int pgsql_namespace(struct ulogd_pluginstance *upi)
 {
-	PGresult *result;
-	char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE)+strlen(schema_ce.u.string)+1];
+	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
+	char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE) + 
+		   strlen(schema_ce(upi->config_kset).u.string) + 1];
 
-	if (!dbh)
+	if (!pi->dbh)
 		return 1;
 
-	sprintf(pgbuf, PGSQL_HAVE_NAMESPACE_TEMPLATE, schema_ce.u.string);
+	sprintf(pgbuf, PGSQL_HAVE_NAMESPACE_TEMPLATE,
+		schema_ce(upi->config_kset).u.string);
 	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
 	
-	result = PQexec(dbh, pgbuf);
-	if (!result) {
+	pi->pgres = PQexec(pi->dbh, pgbuf);
+	if (!pi->pgres) {
 		ulogd_log(ULOGD_DEBUG, "\n result false");
 		return 1;
 	}
 
-	if (PQresultStatus(result) == PGRES_TUPLES_OK) {
-		ulogd_log(ULOGD_DEBUG, "using schema %s\n", schema_ce.u.string);
-		pgsql_have_schemas = 1;
+	if (PQresultStatus(pi->pgres) == PGRES_TUPLES_OK) {
+		ulogd_log(ULOGD_DEBUG, "using schema %s\n",
+			  schema_ce(upi->config_kset).u.string);
+		pi->db_inst.schema = schema_ce(upi->config_kset).u.string;
 	} else {
-		pgsql_have_schemas = 0;
+		pi->db_inst.schema = NULL;
 	}
 
-	PQclear(result);
+	PQclear(pi->pgres);
 	
 	return 0;
 }
@@ -224,20 +226,21 @@
 static int get_columns_pgsql(struct ulogd_pluginstance *upi)
 {
 	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
-	PGresult *result;
 	char pgbuf[strlen(PGSQL_GETCOLUMN_TEMPLATE_SCHEMA)
-		   + strlen(table) + strlen(schema_ce.u.string) + 2];
-	int intaux;
+		   + strlen(table_ce(upi->config_kset).u.string) 
+		   + strlen(pi->db_inst.schema) + 2];
+	int i;
 
 	if (!pi->dbh) {
 		ulogd_log(ULOGD_ERROR, "no database handle\n");
 		return 1;
 	}
 
-	if (pgsql_have_schemas) {
-		snprintf(pgbuf, sizeof(pgbuf)-1, PGSQL_GETCOLUMN_TEMPLATE_SCHEMA,
+	if (pi->db_inst.schema) {
+		snprintf(pgbuf, sizeof(pgbuf)-1,
+			 PGSQL_GETCOLUMN_TEMPLATE_SCHEMA,
 			 table_ce(upi->config_kset).u.string,
-			 schema_ce(upi->config_kset).u.string);
+			 pi->db_inst.schema);
 	} else {
 		snprintf(pgbuf, sizeof(pgbuf)-1, PGSQL_GETCOLUMN_TEMPLATE,
 			 table_ce(upi->config_kset).u.string);
@@ -245,13 +248,13 @@
 
 	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
 
-	result = PQexec(dbh, pgbuf);
-	if (!result) {
+	pi->pgres = PQexec(pi->dbh, pgbuf);
+	if (!pi->pgres) {
 		ulogd_log(ULOGD_DEBUG, "result false");
 		return -1;
 	}
 
-	if (PQresultStatus(result) != PGRES_TUPLES_OK) {
+	if (PQresultStatus(pi->pgres) != PGRES_TUPLES_OK) {
 		ulogd_log(ULOGD_DEBUG, "pres_command_not_ok");
 		return -1;
 	}
@@ -259,7 +262,7 @@
 	if (upi->input.keys)
 		free(upi->input.keys);
 
-	upi->input.num_keys = PQntuples(result);
+	upi->input.num_keys = PQntuples(pi->pgres);
 	ulogd_log(ULOGD_DEBUG, "%u fields in table\n", upi->input.num_keys);
 	upi->input.keys = malloc(sizeof(struct ulogd_key) *
 						upi->input.num_keys);
@@ -272,13 +275,13 @@
 	memset(upi->input.keys, 0, sizeof(struct ulogd_key) *
 						upi->input.num_keys);
 
-	for (intaux = 0; intaux < PQntuples(result); intaux++) {
+	for (i = 0; i < PQntuples(pi->pgres); i++) {
 		char buf[ULOGD_MAX_KEYLEN+1];
 		char *underscore;
 		int id;
 
 		/* replace all underscores with dots */
-		strncpy(buf, PQgetvalue(result, intaux, 0), ULOGD_MAX_KEYLEN);
+		strncpy(buf, PQgetvalue(pi->pgres, i, 0), ULOGD_MAX_KEYLEN);
 		while ((underscore = strchr(buf, '_')))
 			*underscore = '.';
 
@@ -290,7 +293,7 @@
 
 	/* FIXME: id? */
 
-	PQclear(result);
+	PQclear(pi->pgres);
 	return 0;
 }
 
@@ -298,7 +301,9 @@
 {
 	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
 
-	return PQfinish(pi->dbh);
+	PQfinish(pi->dbh);
+
+	return 0;
 }
 
 /* make connection and select database */
@@ -349,13 +354,13 @@
 		strcat(connstr, pass);
 	}
 	
-	dbh = PQconnectdb(connstr);
-	if (PQstatus(dbh) != CONNECTION_OK) {
+	pi->dbh = PQconnectdb(connstr);
+	if (PQstatus(pi->dbh) != CONNECTION_OK) {
 		close_db(upi);
 		return -1;
 	}
 
-	if (pgsql_namespace()) {
+	if (pgsql_namespace(upi)) {
 		ulogd_log(ULOGD_ERROR, "unable to test for pgsql schemas\n");
 		close_db(upi);
 		return -1;
@@ -367,7 +372,7 @@
 static int escape_string_pgsql(struct ulogd_pluginstance *upi,
 			       char *dst, const char *src, unsigned int len)
 {
-	PQescapeString(dst, src, strlen(res->value.ptr)); 
+	PQescapeString(dst, src, strlen(src)); 
 	return 0;
 }
 
@@ -376,7 +381,7 @@
 {
 	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
 
-	pi->pgres = PQexec(dbh, stmt);
+	pi->pgres = PQexec(pi->dbh, stmt);
 	if (!pi->pgres || PQresultStatus(pi->pgres) != PGRES_COMMAND_OK)
 		return -1;
 
@@ -403,7 +408,7 @@
 {
 	struct pgsql_instance *pi = (struct pgsql_instance *) upi->private;
 
-	di->driver = &db_driver_pgsql;
+	pi->db_inst.driver = &db_driver_pgsql;
 
 	return configure_db(upi, stack);
 }
@@ -420,16 +425,16 @@
 	},
 	.config_kset 	= &pgsql_kset,
 	.priv_size	= sizeof(struct pgsql_instance),
-	.start		= &start_pgsql,
+	.start		= &start_db,
 	.stop		= &stop_db,
 	.signal		= &signal_db,
-	.interp		= &interp_pgsql,
+	.interp		= &interp_db,
 	.version	= ULOGD_VERSION,
 };
 
 void __attribute__ ((constructor)) init(void);
 
-void _init(void)
+void init(void)
 {
 	ulogd_register_plugin(&pgsql_plugin);
 }




More information about the netfilter-cvslog mailing list