From c781e3866950bf2c539b2f0bcd9ce422e038b82f Mon Sep 17 00:00:00 2001 From: laforge Date: Wed, 9 Feb 2005 15:21:24 +0000 Subject: port Sven Schuster's patch to add user-specified mysql port number --- ulogd/mysql/ulogd_MYSQL.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'ulogd/mysql') diff --git a/ulogd/mysql/ulogd_MYSQL.c b/ulogd/mysql/ulogd_MYSQL.c index 894098f..0e46cc9 100644 --- a/ulogd/mysql/ulogd_MYSQL.c +++ b/ulogd/mysql/ulogd_MYSQL.c @@ -1,4 +1,4 @@ -/* ulogd_MYSQL.c, Version $Revision: 1.15 $ +/* ulogd_MYSQL.c, Version $Revision$ * * ulogd output plugin for logging to a MySQL database * @@ -29,6 +29,8 @@ * See ulogd/doc/mysql.table.ipaddr-as-string as an example. * BE WARNED: This has _WAY_ less performance during table searches. * + * 09 Feb 2005, Sven Schuster : + * Added the "port" parameter to specify ports different from 3306 */ #include @@ -99,6 +101,12 @@ static config_entry_t table_ce = { .options = CONFIG_OPT_MANDATORY, }; +static config_entry_t port_ce = { + .next = &table_ce, + .key = "port", + .type = CONFIG_TYPE_INT, +}; + /* our main output function, called by ulogd */ static int mysql_output(ulog_iret_t *result) { @@ -314,13 +322,14 @@ static int mysql_get_columns(const char *table) } /* make connection and select database */ -static int mysql_open_db(char *server, char *user, char *pass, char *db) +static int mysql_open_db(char *server, int port, char *user, char *pass, + char *db) { dbh = mysql_init(NULL); if (!dbh) return 1; - if (!mysql_real_connect(dbh, server, user, pass, db, 0, NULL, 0)) + if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0)) return 1; return 0; @@ -329,9 +338,9 @@ static int mysql_open_db(char *server, char *user, char *pass, char *db) static int mysql_init(void) { /* have the opts parsed */ - config_parse_file("MYSQL", &table_ce); + config_parse_file("MYSQL", &port_ce); - if (mysql_open_db(host_ce.u.string, user_ce.u.string, + if (mysql_open_db(host_ce.u.string, port_ce.u.value, user_ce.u.string, pass_ce.u.string, db_ce.u.string)) { ulogd_log(ULOGD_ERROR, "can't establish database connection\n"); return -1; -- cgit v1.2.3