From 0eb391e9f9e44f15c03f1d8d5414c806413f50fb Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sat, 17 Apr 2004 15:14:12 +0000 Subject: beginnings of postgresql driver integrated into autoconf removed log_error from apache20.h (aliased to ap_log_rerror) --- diff --git a/Documentation/README b/Documentation/README index 7ff3241..dd40351 100644 --- a/Documentation/README +++ b/Documentation/README @@ -3,4 +3,5 @@ files here are derived from it. To read the HTML docs, open manual.html in your browser. -To generate other formats of the documentation use xmlto to convert the xml file. +To generate other formats of the documentation use xmlto or your favorite +xslt docbook converter to convert the xml file. diff --git a/Documentation/manual.xml b/Documentation/manual.xml index d7dfc12..0490cc6 100644 --- a/Documentation/manual.xml +++ b/Documentation/manual.xml @@ -1,7 +1,7 @@ - + eddie <at> omegaware <dot> com"> +urkle <at> outoforder <dot> cc"> ]>
@@ -12,7 +12,7 @@ Conversion from Lyx to DocBook Current Maintainer -
eddie <at> omegaware <dot> com
+
&EmailContact;
@@ -98,9 +98,13 @@ The actual logging code was taken from the already existing flat file text modules, so all that credit goes to the Apache Software Foundation. The MySQL routines and directives were added by Zeev Suraski <bourbon@netvision.net.il>. All changes from 1.06+ and the new documentation were added by Chris Powell chris <at> grubbybaby <dot> com. It seems that the module had fallen into the "un-maintained" category -- it had not been updated since 1998 -- so Chris adopted it as the new maintainer. - In December of 2003, Edward Rudd eddie <at> omegaware <dot> com porting the module to Apache 2.0, cleaning up the code, converting the documentation to DocBook, optimizing the main logging loop, and added the much anticipated database abstraction layer. + In December of 2003, Edward Rudd &EmailContact; porting the module to Apache 2.0, cleaning up the code, converting the documentation to DocBook, optimizing the main logging loop, and added the much anticipated database abstraction layer. As of February 2004, Chris Powell handed over maintenance of the module over to Edward Rudd. So you should contact Edward Rudd about the module from now on. + + Mailing Lists + A general discussion and support mailing list is provided for mod_log_sq at lists.outoforder.cc. To subscribe to the mailing list send a blank e-mail to mod_log_sql-subscribe@lists.outoforder.cc. The list archives can be accessed via Gmane.org's mailng list gateway via any new reader news://news.gmane.org/gmane.comp.apache.mod-log-sql, or via a web browser at http://news.gmane.org/gmane.comp.apache.mod-log-sql. + Installation @@ -1227,7 +1231,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; Who's using mod_log_sql? - Good question! It would be great to find out! If you are a production-level mod_log_sql user, please contact &MaintainerContact; so that you can be mentioned here. + Good question! It would be great to find out! If you are a production-level mod_log_sql user, please contact eddie at &EmailContact; so that you can be mentioned here. @@ -1277,7 +1281,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg'; I have discovered a bug. Who can I contact? - Please contact &MaintainerContact;, or post a message to the mod_log_sql mailing list. Your comments, suggestions, bugfixes, bug catches, and usage testimonials are always welcome. As free software, mod_log_sql is intended to be a community effort -- any code contributions or other ideas will be fully and openly credited, of course. + Please contact Edward Rudd at &EmailContact;, or post a message to the mod_log_sql . Your comments, suggestions, bugfixes, bug catches, and usage testimonials are always welcome. As free software, mod_log_sql is intended to be a community effort -- any code contributions or other ideas will be fully and openly credited, of course. diff --git a/INSTALL b/INSTALL index 033a3ff..38fb9bd 100644 --- a/INSTALL +++ b/INSTALL @@ -1,3 +1,20 @@ This document has been superseded by the new documentation in the Documentation/ directory. There you will find the docs in a variety of formats, including PostScript, plaintext, and HTML. + +Basic overview is.. + +./configure --with-apxs=/path/to/apxs --enable-ssl + +gmake + +gmake install + + +edit httpd.conf and add the following. + +LoadModule log_sql_module modules/mod_log_sql.so +LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so + +LoadModule log_sql_ssl_module modules/mod_log_sql_ssl.so + diff --git a/Makefile.in b/Makefile.in index 93acec9..b6391e1 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,12 +31,22 @@ mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ mysqlCFLAGS = @MYSQL_CFLAGS@ mysqlNAME = log_sql_mysql +pgsqlSOURCES = @PACKAGE_NAME@_pgsql.c +pgsqlTARGET = @PACKAGE_NAME@_pgsql@APXS_EXTENSION@ +pgsqlLDADD = @PGSQL_LDFLAGS@ @PGSQL_LIBS@ +pgsqlCFLAGS = @PGSQL_CFLAGS@ +pgsqlNAME = log_sql_pgsql + +TARGETS = $(TARGET) + ifeq (@WANT_SSL_MOD@,1) -TARGETS = $(TARGET) $(mysqlTARGET) $(sslTARGET) -else -TARGETS = $(TARGET) $(mysqlTARGET) +TARGETS += $(sslTARGET) endif +TARGETS += $(mysqlTARGET) + +TARGETS += $(pgsqlTARGET) + #Don't modify anything below here PROVIDERS_SUBDIRS = @subdirs@ @@ -85,7 +95,7 @@ TODO: TODO.in $(TARGET): $(SOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(TARGET) $(CFLAGS) \ - $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES) + @DEFS@ @APACHE_DEFS@ $(LDADD) $(SOURCES) $(sslTARGET): $(sslSOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \ @@ -95,6 +105,10 @@ $(mysqlTARGET): $(mysqlSOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(mysqlTARGET) $(mysqlCFLAGS) $(CFLAGS) \ @DEFS@ @APACHE_DEFS@ $(mysqlLDADD) $(mysqlSOURCES) +$(pgsqlTARGET): $(pgsqlSOURCES) $(HEADERS) + @@APXS_BIN@ -c -o $(pgsqlTARGET) $(pgsqlCFLAGS) $(CFLAGS) \ + @DEFS@ @APACHE_DEFS@ $(pgsqlLDADD) $(pgsqlSOURCES) + include: rm -rf include ln -s @APACHE_INCDIR@ include diff --git a/TODO.in b/TODO.in index b8bff60..12bb30c 100644 --- a/TODO.in +++ b/TODO.in @@ -1,16 +1,11 @@ TODO: -* Port connection portion to other DBMS? Genericize the module? Start with - PostgreSQL. (provider mechanism, and libDBI) -* does determining table name in massvirtual mode upon every request - cause performance degradation? If so fix. No other feasable way to fix this, - unless you cache, but then for large amounts of hosts, this can be a waste. +* write alternate DB driver (PostgreSQL, libDBI, mod_*_pool) +* look at forcing table name to ServerName instead of on of the names in + ServerAlias? * LogSQLRotateLogs directive with daily/monthly/weekly/etc. * socket-based middleman daemon with configurable conns, or connect/disconnect. * DBI connection pool when I switch to DBI. * ignore by cookie -* break module into separate code files - SSL already separated. - separate DB implimentation into sub-modules via provider mechanism * investigate thread safety issues Use libmysqlclient_r for threaded MPM (or always?) Add thread locks if using standard mysqlclient diff --git a/apache20.h b/apache20.h index a20c695..9d87588 100644 --- a/apache20.h +++ b/apache20.h @@ -20,17 +20,6 @@ #include "util_time.h" -/*static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); -static inline void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) -{ - static char buff[MAX_STRING_LEN]; - va_list args; - va_start(args, fmt); - apr_vsnprintf(buff,MAX_STRING_LEN, fmt,args); - ap_log_error(file,line,level,0,s,"%s",buff); - va_end(args); -}*/ - #define log_error ap_log_error #endif /* APACHE20_H */ diff --git a/configure.ac b/configure.ac index c93d224..91f4b81 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,12 @@ AC_CHECK_HEADERS(limits.h) AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) +PGSQL_LIBS=-lpq + +AC_SUBST(PGSQL_LIBS) +AC_SUBST(PGSQL_LDFLAGS) +AC_SUBST(PGSQL_CFLAGS) + dnl Write config.status and the Makefile AC_OUTPUT(Makefile diff --git a/functions.h b/functions.h index 6163b21..7281588 100644 --- a/functions.h +++ b/functions.h @@ -1,4 +1,5 @@ /* $Id$ */ + /* Begin the individual functions that, given a request r, * extract the needed information from it and return the * value to the calling entity. diff --git a/functions20.h b/functions20.h index 42fe664..ee58513 100644 --- a/functions20.h +++ b/functions20.h @@ -1,5 +1,5 @@ /* $Id$ */ -/* functions */ + static const char *extract_bytes_sent(request_rec *r, char *a) { if (!r->sent_bodyct || !r->bytes_sent) { diff --git a/mod_log_sql.c b/mod_log_sql.c index 7c16ab9..83a303a 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -1,4 +1,12 @@ -/* $Id: mod_log_sql.c,v 1.20 2004/03/05 00:30:58 urkle Exp $ */ +/* $Id$ */ + +#if defined(WITH_APACHE20) +# include "apache20.h" +#elif defined(WITH_APACHE13) +# include "apache13.h" +#else +# error Unsupported Apache version +#endif #ifdef HAVE_CONFIG_H /* Undefine these to prevent conflicts between Apache ap_config_auto.h and @@ -13,14 +21,6 @@ #include "config.h" #endif -#if defined(WITH_APACHE20) -# include "apache20.h" -#elif defined(WITH_APACHE13) -# include "apache13.h" -#else -# error Unsupported Apache version -#endif - #if APR_HAVE_UNISTD_H #include #endif diff --git a/mod_log_sql.prj b/mod_log_sql.prj index e88b2c6..bb04bb2 100644 --- a/mod_log_sql.prj +++ b/mod_log_sql.prj @@ -66,10 +66,11 @@ module.source.type= module.source.expanded=1 module.source.files=\ mod_log_sql.c\ - make_combined_log.pl\ contrib/mysql_import_combined_log.pl\ mod_log_sql_ssl.c\ - mod_log_sql_mysql.c + mod_log_sql_mysql.c\ + contrib/make_combined_log.pl\ + mod_log_sql_pgsql.c module.pixmap.name=. module.pixmap.type= diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c index 5a654f3..3749d64 100644 --- a/mod_log_sql_mysql.c +++ b/mod_log_sql_mysql.c @@ -1,6 +1,4 @@ -/* $Id: mod_log_sql_mysql.c,v 1.4 2004/03/05 00:30:58 urkle Exp $ */ -#include "mysql.h" -#include "mysqld_error.h" +/* $Id$ */ #if defined(WITH_APACHE20) # include "apache20.h" @@ -25,6 +23,9 @@ #include "mod_log_sql.h" +#include "mysql.h" +#include "mysqld_error.h" + /* The enduser won't modify these */ #define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away") diff --git a/mod_log_sql_pgsql.c b/mod_log_sql_pgsql.c index 8fb0f9e..7ac4053 100644 --- a/mod_log_sql_pgsql.c +++ b/mod_log_sql_pgsql.c @@ -8,6 +8,7 @@ # error Unsupported Apache version #endif + #ifdef HAVE_CONFIG_H /* Undefine these to prevent conflicts between Apache ap_config_auto.h and * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. @@ -23,6 +24,13 @@ #include "mod_log_sql.h" +#include "libpq-fe.h" + +typedef struct { + PGconn *PG; + char *connectioninfo; +} pg_conn_rec; + /* Connect to the MYSQL database */ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnection *db) { @@ -33,7 +41,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio const char *s_tcpport = apr_table_get(db->parms,"port"); unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306; const char *socketfile = apr_table_get(db->parms,"socketfile"); - MYSQL *dblink = db->handle; + pg_conn_rec *dblink = db->handle; dblink = mysql_init(dblink); db->handle = (void *)dblink; @@ -43,7 +51,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio socketfile = "/var/lib/mysql/mysql.sock"; } - if (mysql_real_connect(dblink, host, user, passwd, database, tcpport, + if (PQconnectdb(dblink, host, user, passwd, database, tcpport, socketfile, 0)) { log_error(APLOG_MARK,APLOG_DEBUG,0, s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", host, tcpport, database, user, socketfile); @@ -60,7 +68,7 @@ static logsql_opendb_ret log_sql_pgsql_connect(server_rec *s, logsql_dbconnectio /* Close the DB link */ static void log_sql_pgsql_close(logsql_dbconnection *db) { - mysql_close((MYSQL *)db->handle); + PQfinish(((pg_conn_rec *)db->handle)->PG); } /* Routine to escape the 'dangerous' characters that would otherwise @@ -113,7 +121,7 @@ static logsql_query_ret log_sql_pgsql_query(request_rec *r,logsql_dbconnection * unsigned int real_error = 0; /*const char *real_error_str = NULL;*/ - MYSQL *dblink = (MYSQL *)db->handle; + pg_conn_rec *dblink = db->handle; if (!dblink) { return LOGSQL_QUERY_NOLINK; @@ -154,7 +162,7 @@ static logsql_table_ret log_sql_pgsql_create(request_rec *r, logsql_dbconnection char *create_suffix = NULL; char *create_sql; - MYSQL *dblink = (MYSQL *)db->handle; + pg_conn_rec *dblink = db->handle; /* if (!global_config.createtables) { return APR_SUCCESS; @@ -230,11 +238,11 @@ static logsql_table_ret log_sql_pgsql_create(request_rec *r, logsql_dbconnection static char *supported_drivers[] = {"pgsql",NULL}; static logsql_dbdriver pgsql_driver = { supported_drivers, - log_sql_mysql_connect, /* open DB connection */ - log_sql_mysql_close, /* close DB connection */ - log_sql_mysql_escape, /* escape query */ - log_sql_mysql_query, /* insert query */ - log_sql_mysql_create /* create table */ + log_sql_pgsql_connect, /* open DB connection */ + log_sql_pgsql_close, /* close DB connection */ + log_sql_pgsql_escape, /* escape query */ + log_sql_pgsql_query, /* insert query */ + log_sql_pgsql_create /* create table */ }; LOGSQL_REGISTER(pgsql) { diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c index ca4ced7..8b792db 100644 --- a/mod_log_sql_ssl.c +++ b/mod_log_sql_ssl.c @@ -1,5 +1,4 @@ -/* $Id: mod_log_sql_ssl.c,v 1.7 2004/03/05 00:30:58 urkle Exp $ */ -/* mod_log_sql_ssl */ +/* $Id$ */ #if defined(WITH_APACHE20) # include "apache20.h" @@ -23,6 +22,7 @@ #endif #include "mod_log_sql.h" + #include "mod_ssl.h" #if defined(WITH_APACHE20) -- cgit v0.9.2