summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
-rw-r--r--.project60
-rw-r--r--Makefile.in28
-rw-r--r--TODO.in3
-rw-r--r--configure.ac12
-rw-r--r--mod_log_sql.c26
-rw-r--r--mod_log_sql.h4
-rw-r--r--mod_log_sql_dbd.c132
-rw-r--r--mod_log_sql_dbi.c2
-rw-r--r--mod_log_sql_mysql.c2
9 files changed, 211 insertions, 58 deletions
diff --git a/.project b/.project
index db2ba74..9af17e9 100644
--- a/.project
+++ b/.project
@@ -3,19 +3,16 @@
3 <name>mod_log_sql</name> 3 <name>mod_log_sql</name>
4 <comment></comment> 4 <comment></comment>
5 <projects> 5 <projects>
6 <project>includes</project>
6 </projects> 7 </projects>
7 <buildSpec> 8 <buildSpec>
8 <buildCommand> 9 <buildCommand>
9 <name>org.eclipse.cdt.make.core.makeBuilder</name> 10 <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10 <triggers>clean,full,incremental,</triggers> 11 <triggers>clean,full,incremental,</triggers>
11 <arguments> 12 <arguments>
12 <dictionary> 13 <dictionary>
13 <key>org.eclipse.cdt.make.core.build.arguments</key> 14 <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
14 <value></value> 15 <value>all</value>
15 </dictionary>
16 <dictionary>
17 <key>org.eclipse.cdt.core.errorOutputParser</key>
18 <value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser;</value>
19 </dictionary> 16 </dictionary>
20 <dictionary> 17 <dictionary>
21 <key>org.eclipse.cdt.make.core.enableAutoBuild</key> 18 <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
@@ -26,47 +23,47 @@
26 <value></value> 23 <value></value>
27 </dictionary> 24 </dictionary>
28 <dictionary> 25 <dictionary>
29 <key>org.eclipse.cdt.make.core.enableFullBuild</key> 26 <key>org.eclipse.cdt.make.core.buildLocation</key>
30 <value>true</value> 27 <value>${workspace_loc:/mod_log_sql/Linux GCC}</value>
31 </dictionary> 28 </dictionary>
32 <dictionary> 29 <dictionary>
33 <key>org.eclipse.cdt.make.core.build.target.inc</key> 30 <key>?name?</key>
34 <value>all</value> 31 <value></value>
35 </dictionary> 32 </dictionary>
36 <dictionary> 33 <dictionary>
37 <key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key> 34 <key>org.eclipse.cdt.make.core.enableFullBuild</key>
38 <value>true</value> 35 <value>true</value>
39 </dictionary> 36 </dictionary>
40 <dictionary> 37 <dictionary>
41 <key>org.eclipse.cdt.make.core.build.location</key> 38 <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
42 <value></value> 39 <value>true</value>
43 </dictionary> 40 </dictionary>
44 <dictionary> 41 <dictionary>
45 <key>org.eclipse.cdt.make.core.build.target.clean</key> 42 <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
46 <value>clean</value> 43 <value>clean</value>
47 </dictionary> 44 </dictionary>
48 <dictionary> 45 <dictionary>
49 <key>org.eclipse.cdt.make.core.build.command</key>
50 <value>sshmake</value>
51 </dictionary>
52 <dictionary>
53 <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
54 <value>true</value>
55 </dictionary>
56 <dictionary>
57 <key>org.eclipse.cdt.make.core.append_environment</key> 46 <key>org.eclipse.cdt.make.core.append_environment</key>
58 <value>true</value> 47 <value>true</value>
59 </dictionary> 48 </dictionary>
60 <dictionary> 49 <dictionary>
61 <key>org.eclipse.cdt.make.core.build.target.full</key> 50 <key>org.eclipse.cdt.make.core.contents</key>
62 <value>clean all</value> 51 <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
63 </dictionary> 52 </dictionary>
64 <dictionary> 53 <dictionary>
65 <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key> 54 <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
66 <value>false</value> 55 <value>false</value>
67 </dictionary> 56 </dictionary>
68 <dictionary> 57 <dictionary>
69 <key>org.eclipse.cdt.make.core.build.target.auto</key> 58 <key>org.eclipse.cdt.make.core.buildArguments</key>
59 <value>${project_name} make -k</value>
60 </dictionary>
61 <dictionary>
62 <key>org.eclipse.cdt.make.core.buildCommand</key>
63 <value>${HOME}/bin/sshmake</value>
64 </dictionary>
65 <dictionary>
66 <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
70 <value>all</value> 67 <value>all</value>
71 </dictionary> 68 </dictionary>
72 <dictionary> 69 <dictionary>
@@ -76,19 +73,14 @@
76 </arguments> 73 </arguments>
77 </buildCommand> 74 </buildCommand>
78 <buildCommand> 75 <buildCommand>
79 <name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name> 76 <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
80 <arguments>
81 </arguments>
82 </buildCommand>
83 <buildCommand>
84 <name>de.loskutov.FileSync.FSBuilder</name>
85 <arguments> 77 <arguments>
86 </arguments> 78 </arguments>
87 </buildCommand> 79 </buildCommand>
88 </buildSpec> 80 </buildSpec>
89 <natures> 81 <natures>
90 <nature>org.eclipse.cdt.core.cnature</nature> 82 <nature>org.eclipse.cdt.core.cnature</nature>
91 <nature>org.eclipse.cdt.make.core.makeNature</nature> 83 <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
92 <nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature> 84 <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
93 </natures> 85 </natures>
94</projectDescription> 86</projectDescription>
diff --git a/Makefile.in b/Makefile.in
index 2865d5f..2647d2e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -77,6 +77,16 @@ ifeq (@WANT_DBI_MOD@,1)
77TARGETS += $(dbiTARGET) 77TARGETS += $(dbiTARGET)
78endif 78endif
79 79
80dbdSOURCES = @PACKAGE_NAME@_dbd.c
81dbdTARGET = @PACKAGE_NAME@_dbd@APXS_EXTENSION@
82dbdLDADD =
83dbdCFLAGS =
84dbdNAME = log_sql_dbd
85
86ifeq (@WANT_DBD_MOD@,1)
87TARGETS += $(dbdTARGET)
88endif
89
80#Don't modify anything below here 90#Don't modify anything below here
81 91
82PROVIDERS_SUBDIRS = @subdirs@ 92PROVIDERS_SUBDIRS = @subdirs@
@@ -85,13 +95,13 @@ srcdir = @abs_srcdir@
85builddir = @abs_builddir@ 95builddir = @abs_builddir@
86 96
87OBJ = $(coreSOURCES:.c=.o) $(logioSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \ 97OBJ = $(coreSOURCES:.c=.o) $(logioSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \
88 $(dbiSOURCES:.c=.o) $(pgsqlSOURCES:.c=.o) 98 $(dbiSOURCES:.c=.o) $(pgsqlSOURCES:.c=.o) $(dbdSOURCES:.c=.o)
89 99
90LO = $(coreSOURCES:.c=.lo) $(logioSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \ 100LO = $(coreSOURCES:.c=.lo) $(logioSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \
91 $(dbiSOURCES:.c=.lo) $(pgsqlSOURCES:.c=.lo) 101 $(dbiSOURCES:.c=.lo) $(pgsqlSOURCES:.c=.lo) $(dbdSOURCES:.c=.lo)
92 102
93SLO = $(coreSOURCES:.c=.slo) $(logioSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \ 103SLO = $(coreSOURCES:.c=.slo) $(logioSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \
94 $(dbiSOURCES:.c=.slo) $(pgsqlSOURCES:.c=.slo) 104 $(dbiSOURCES:.c=.slo) $(pgsqlSOURCES:.c=.slo) $(dbdSOURCES:.c=.slo)
95 105
96STD_DIST = install-sh \ 106STD_DIST = install-sh \
97 config.sub \ 107 config.sub \
@@ -104,7 +114,7 @@ STD_DIST = install-sh \
104 config.h.in 114 config.h.in
105 115
106DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(coreSOURCES) $(HEADERS) \ 116DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(coreSOURCES) $(HEADERS) \
107 $(sslSOURCES) $(logioSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES) 117 $(sslSOURCES) $(logioSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES) $(dbdSOURCES)
108 118
109all: $(TARGETS) all-subdirs 119all: $(TARGETS) all-subdirs
110 120
@@ -150,6 +160,11 @@ $(dbiTARGET): $(dbiSOURCES) $(HEADERS)
150 @@APXS_BIN@ -c -o $(dbiTARGET) $(dbiCFLAGS) $(CFLAGS) \ 160 @@APXS_BIN@ -c -o $(dbiTARGET) $(dbiCFLAGS) $(CFLAGS) \
151 @DEFS@ @AP_DEFS@ $(dbiLDADD) $(dbiSOURCES) 161 @DEFS@ @AP_DEFS@ $(dbiLDADD) $(dbiSOURCES)
152 162
163$(dbdTARGET): $(dbdSOURCES) $(HEADERS)
164 @@APXS_BIN@ -c -o $(dbdTARGET) $(dbdCFLAGS) $(CFLAGS) \
165 @DEFS@ @AP_DEFS@ $(dbdLDADD) $(dbdSOURCES)
166
167
153install: $(TARGETS) install-subdirs 168install: $(TARGETS) install-subdirs
154 @@APXS_BIN@ -n $(coreNAME) -i $(coreTARGET); \ 169 @@APXS_BIN@ -n $(coreNAME) -i $(coreTARGET); \
155 if test @WANT_MYSQL_MOD@ -eq 1; then \ 170 if test @WANT_MYSQL_MOD@ -eq 1; then \
@@ -161,6 +176,9 @@ install: $(TARGETS) install-subdirs
161 if test @WANT_DBI_MOD@ -eq 1; then \ 176 if test @WANT_DBI_MOD@ -eq 1; then \
162 @APXS_BIN@ -n $(dbiNAME) -i $(dbiTARGET); \ 177 @APXS_BIN@ -n $(dbiNAME) -i $(dbiTARGET); \
163 fi; \ 178 fi; \
179 if test @WANT_DBD_MOD@ -eq 1; then \
180 @APXS_BIN@ -n $(dbdNAME) -i $(dbdTARGET); \
181 fi; \
164 if test @WANT_SSL_MOD@ -eq 1; then \ 182 if test @WANT_SSL_MOD@ -eq 1; then \
165 @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \ 183 @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \
166 fi; \ 184 fi; \
@@ -241,7 +259,7 @@ stamp-h: config.h.in config.status
241 ./config.status 259 ./config.status
242 260
243$(srcdir)/configure: configure.ac aclocal.m4 261$(srcdir)/configure: configure.ac aclocal.m4
244 cd $(srcdir) && autoconf-2.53 262 cd $(srcdir) && autoconf
245 263
246Makefile: Makefile.in config.status 264Makefile: Makefile.in config.status
247 ./config.status 265 ./config.status
diff --git a/TODO.in b/TODO.in
index 0d871f6..bf6b624 100644
--- a/TODO.in
+++ b/TODO.in
@@ -1,5 +1,5 @@
1TODO: 1TODO:
2* verify a db driver has been loaded. 2* restructure to be more friendly toward DBD pooling
3* validate table names before trying to log them. 3* validate table names before trying to log them.
4* write alternate DB driver (PostgreSQL, libDBI, mod_*_pool) 4* write alternate DB driver (PostgreSQL, libDBI, mod_*_pool)
5* look at forcing table name to ServerName instead of on of the names in 5* look at forcing table name to ServerName instead of on of the names in
@@ -7,7 +7,6 @@ TODO:
7* LogSQLRotateLogs directive with daily/monthly/weekly/etc. 7* LogSQLRotateLogs directive with daily/monthly/weekly/etc.
8* socket-based middleman daemon with configurable conns, or connect/disconnect. 8* socket-based middleman daemon with configurable conns, or connect/disconnect.
9* DBI connection pooling. 9* DBI connection pooling.
10* apr_dbd backend driver
11* ignore by cookie 10* ignore by cookie
12* investigate thread safety issues 11* investigate thread safety issues
13 Use libmysqlclient_r for threaded MPM (or always?) 12 Use libmysqlclient_r for threaded MPM (or always?)
diff --git a/configure.ac b/configure.ac
index 8a348dc..55de120 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,8 +26,17 @@ if test $AP_VERSION = "2.0"; then
26else 26else
27 WANT_LOGIO_MOD=0 27 WANT_LOGIO_MOD=0
28fi 28fi
29
29AC_SUBST(WANT_LOGIO_MOD) 30AC_SUBST(WANT_LOGIO_MOD)
30 31
32if test $AP_VERSION = "2.0"; then
33 WANT_DBD_MOD=1
34else
35 WANT_DBD_MOD=0
36fi
37
38AC_SUBST(WANT_DBD_MOD)
39
31CHECK_MYSQL( 40CHECK_MYSQL(
32 WANT_MYSQL_MOD=1, 41 WANT_MYSQL_MOD=1,
33 AC_MSG_WARN([*** Mysql client libraries not found!]) 42 AC_MSG_WARN([*** Mysql client libraries not found!])
@@ -105,6 +114,9 @@ fi
105if test $WANT_DBI_MOD -eq 1; then 114if test $WANT_DBI_MOD -eq 1; then
106 AC_MSG_RESULT([ libDBI Driver]) 115 AC_MSG_RESULT([ libDBI Driver])
107fi 116fi
117if test $WANT_DBD_MOD -eq 1; then
118 AC_MSG_RESULT([ APR DBD Driver])
119fi
108if test $OOO_MAINTAIN -eq 1; then 120if test $OOO_MAINTAIN -eq 1; then
109 AC_MSG_RESULT([Maintainer mode is on. -Werror is in effect]) 121 AC_MSG_RESULT([Maintainer mode is on. -Werror is in effect])
110fi 122fi
diff --git a/mod_log_sql.c b/mod_log_sql.c
index b6a5c83..d319e97 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1201,7 +1201,7 @@ static int log_sql_transaction(request_rec *orig)
1201 fields = apr_pstrcat(r->pool, fields, (showcomma ? "," : ""), 1201 fields = apr_pstrcat(r->pool, fields, (showcomma ? "," : ""),
1202 item->sql_field_name, NULL); 1202 item->sql_field_name, NULL);
1203 values = apr_pstrcat(r->pool, values, (showcomma ? "," : ""), 1203 values = apr_pstrcat(r->pool, values, (showcomma ? "," : ""),
1204 global_config.driver->escape(formatted_item, r->pool,&global_config.db), NULL); 1204 global_config.driver->escape(r, formatted_item, r->pool,&global_config.db), NULL);
1205 showcomma = 1; 1205 showcomma = 1;
1206 } 1206 }
1207 1207
@@ -1216,11 +1216,11 @@ static int log_sql_transaction(request_rec *orig)
1216 itemsets = apr_pstrcat(r->pool, itemsets, 1216 itemsets = apr_pstrcat(r->pool, itemsets,
1217 (i > 0 ? "," : ""), 1217 (i > 0 ? "," : ""),
1218 "(", 1218 "(",
1219 global_config.driver->escape(unique_id, r->pool, &global_config.db), 1219 global_config.driver->escape(r, unique_id, r->pool, &global_config.db),
1220 ",", 1220 ",",
1221 global_config.driver->escape(*ptrptr, r->pool,&global_config.db), 1221 global_config.driver->escape(r, *ptrptr, r->pool,&global_config.db),
1222 ",", 1222 ",",
1223 global_config.driver->escape(theitem, r->pool,&global_config.db), 1223 global_config.driver->escape(r, theitem, r->pool,&global_config.db),
1224 ")", 1224 ")",
1225 NULL); 1225 NULL);
1226 i++; 1226 i++;
@@ -1244,11 +1244,11 @@ static int log_sql_transaction(request_rec *orig)
1244 itemsets = apr_pstrcat(r->pool, itemsets, 1244 itemsets = apr_pstrcat(r->pool, itemsets,
1245 (i > 0 ? "," : ""), 1245 (i > 0 ? "," : ""),
1246 "(", 1246 "(",
1247 global_config.driver->escape(unique_id, r->pool, &global_config.db), 1247 global_config.driver->escape(r,unique_id, r->pool, &global_config.db),
1248 ",", 1248 ",",
1249 global_config.driver->escape(*ptrptr, r->pool,&global_config.db), 1249 global_config.driver->escape(r,*ptrptr, r->pool,&global_config.db),
1250 ",", 1250 ",",
1251 global_config.driver->escape(theitem, r->pool,&global_config.db), 1251 global_config.driver->escape(r,theitem, r->pool,&global_config.db),
1252 ")", 1252 ")",
1253 NULL); 1253 NULL);
1254 i++; 1254 i++;
@@ -1273,11 +1273,11 @@ static int log_sql_transaction(request_rec *orig)
1273 itemsets = apr_pstrcat(r->pool, itemsets, 1273 itemsets = apr_pstrcat(r->pool, itemsets,
1274 (i > 0 ? "," : ""), 1274 (i > 0 ? "," : ""),
1275 "(", 1275 "(",
1276 global_config.driver->escape(unique_id, r->pool, &global_config.db), 1276 global_config.driver->escape(r,unique_id, r->pool, &global_config.db),
1277 ",", 1277 ",",
1278 global_config.driver->escape(*ptrptr, r->pool,&global_config.db), 1278 global_config.driver->escape(r,*ptrptr, r->pool,&global_config.db),
1279 ",", 1279 ",",
1280 global_config.driver->escape(theitem, r->pool,&global_config.db), 1280 global_config.driver->escape(r,theitem, r->pool,&global_config.db),
1281 ")", 1281 ")",
1282 NULL); 1282 NULL);
1283 i++; 1283 i++;
@@ -1302,11 +1302,11 @@ static int log_sql_transaction(request_rec *orig)
1302 itemsets = apr_pstrcat(r->pool, itemsets, 1302 itemsets = apr_pstrcat(r->pool, itemsets,
1303 (i > 0 ? "," : ""), 1303 (i > 0 ? "," : ""),
1304 "(", 1304 "(",
1305 global_config.driver->escape(unique_id, r->pool, &global_config.db), 1305 global_config.driver->escape(r,unique_id, r->pool, &global_config.db),
1306 ",", 1306 ",",
1307 global_config.driver->escape(*ptrptr, r->pool,&global_config.db), 1307 global_config.driver->escape(r,*ptrptr, r->pool,&global_config.db),
1308 ",", 1308 ",",
1309 global_config.driver->escape(theitem, r->pool,&global_config.db), 1309 global_config.driver->escape(r,theitem, r->pool,&global_config.db),
1310 ")", 1310 ")",
1311 NULL); 1311 NULL);
1312 i++; 1312 i++;
diff --git a/mod_log_sql.h b/mod_log_sql.h
index 2d20374..c1d9bff 100644
--- a/mod_log_sql.h
+++ b/mod_log_sql.h
@@ -24,7 +24,7 @@
24#define LOGSQL_DECLARE_DATA __declspec(dllimport) 24#define LOGSQL_DECLARE_DATA __declspec(dllimport)
25#endif 25#endif
26 26
27#define LOG_SQL_PLUGIN_VERSION 20070704 27#define LOG_SQL_PLUGIN_VERSION 20080318
28 28
29/* Registration function for extract functions */ 29/* Registration function for extract functions */
30 30
@@ -115,7 +115,7 @@ typedef struct {
115 /* disconnect from the underlying database layer */ 115 /* disconnect from the underlying database layer */
116 void (*disconnect)(logsql_dbconnection *db); 116 void (*disconnect)(logsql_dbconnection *db);
117 /* escape the SQL statement according to database rules */ 117 /* escape the SQL statement according to database rules */
118 const char *(*escape)(const char *from_str, apr_pool_t *p, 118 const char *(*escape)(request_rec *r,const char *from_str, apr_pool_t *p,
119 logsql_dbconnection *db); 119 logsql_dbconnection *db);
120 /* insert a SQL query statement */ 120 /* insert a SQL query statement */
121 logsql_query_ret (*insert)(request_rec *r,logsql_dbconnection *db, 121 logsql_query_ret (*insert)(request_rec *r,logsql_dbconnection *db,
diff --git a/mod_log_sql_dbd.c b/mod_log_sql_dbd.c
new file mode 100644
index 0000000..c78a128
--- /dev/null
+++ b/mod_log_sql_dbd.c
@@ -0,0 +1,132 @@
1/* $Id: mod_log_sql_dbi.c 120 2004-04-17 15:14:12Z urkle@drip.ws $ */
2
3#if defined(WITH_APACHE20)
4# include "apache20.h"
5#else
6# error Unsupported Apache version
7#endif
8
9
10#ifdef HAVE_CONFIG_H
11/* Undefine these to prevent conflicts between Apache ap_config_auto.h and
12 * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt.
13 */
14#undef PACKAGE_BUGREPORT
15#undef PACKAGE_NAME
16#undef PACKAGE_STRING
17#undef PACKAGE_TARNAME
18#undef PACKAGE_VERSION
19
20#include "config.h"
21#endif
22
23#include "mod_log_sql.h"
24
25#include "apr_dbd.h"
26#include "mod_dbd.h"
27
28typedef struct {
29 ap_dbd_t *dbd;
30} request_config_t;
31
32LOGSQL_MODULE_FORWARD(dbd);
33
34static ap_dbd_t *(*dbd_acquire_fn)(request_rec*) = NULL;
35
36static ap_dbd_t *log_sql_dbd_getconnection(request_rec *r)
37{
38 request_config_t *rconf = ap_get_module_config(r->request_config, &LOGSQL_MODULE(dbd));
39 if (!rconf) {
40 rconf = apr_pcalloc(r->pool, sizeof(request_config_t));
41 ap_set_module_config(r->request_config, &LOGSQL_MODULE(dbd), (void *)rconf);
42 rconf->dbd = dbd_acquire_fn(r);
43 }
44 return rconf->dbd;
45}
46
47/* Connect to the database */
48static logsql_opendb_ret log_sql_dbd_connect(server_rec *s, logsql_dbconnection *db)
49{
50 // We are using mod_dbd so we don't do anything here
51 if (!dbd_acquire_fn) {
52 // no mod_dbd return failure
53 log_error(APLOG_MARK,APLOG_ERR,0, s,"mod_log_sql_dbd: mod_dbd is not loaded or available");
54 return LOGSQL_OPENDB_FAIL;
55 } else {
56 return LOGSQL_OPENDB_SUCCESS;
57 }
58}
59
60/* Close the DB link */
61static void log_sql_dbd_close(logsql_dbconnection *db)
62{
63 // mod_dbd handles this, so do nothing
64}
65
66/* Routine to escape the 'dangerous' characters that would otherwise
67 * corrupt the INSERT string: ', \, and "
68 */
69static const char *log_sql_dbd_escape(request_rec *r, const char *from_str, apr_pool_t *p,
70 logsql_dbconnection *db)
71{
72 // Acquire a DBD connection from mod_dbd
73 ap_dbd_t *dbd = log_sql_dbd_getconnection(r);
74 if (!dbd) return NULL;
75
76 if (!from_str)
77 return NULL;
78
79 return apr_pstrcat(p, "'",apr_dbd_escape(dbd->driver, p, from_str, dbd->handle),"'",NULL);
80}
81
82/* Run an insert query and return a categorized error or success */
83static logsql_query_ret log_sql_dbd_query(request_rec *r,logsql_dbconnection *db,
84 const char *query)
85{
86 int ret;
87 const char *err;
88 int affected;
89 // Acquire a DBD connection from mod_dbd
90 ap_dbd_t *dbd = log_sql_dbd_getconnection(r);
91 if (!dbd) return LOGSQL_QUERY_NOLINK;
92
93 // Run the query
94 ret = apr_dbd_query(dbd->driver, dbd->handle, &affected, query);
95 if (ret == 0) {
96 return LOGSQL_QUERY_SUCCESS;
97 } else {
98 // attempt to detect error message
99 err = apr_dbd_error(dbd->driver, dbd->handle, ret);
100 log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "DB Returned error: (%d) %s", ret, err);
101 // Unable to check if "NO SUCH TABLE" due to apr_dbd not mapping error codes to a standard set.
102 return LOGSQL_QUERY_FAIL;
103 }
104}
105
106/* Create table table_name of type table_type. */
107static logsql_table_ret log_sql_dbd_create(request_rec *r, logsql_dbconnection *db,
108 logsql_tabletype table_type, const char *table_name)
109{
110 return LOGSQL_TABLE_FAIL;
111}
112
113static const char *supported_drivers[] = {"dbd",NULL};
114static logsql_dbdriver log_sql_dbd_driver = {
115 "dbd",
116 supported_drivers,
117 log_sql_dbd_connect,/* open DB connection */
118 log_sql_dbd_close, /* close DB connection */
119 log_sql_dbd_escape, /* escape query */
120 log_sql_dbd_query, /* insert query */
121 log_sql_dbd_create /* create table */
122};
123
124LOGSQL_REGISTER(dbd) {
125 dbd_acquire_fn = APR_RETRIEVE_OPTIONAL_FN(ap_dbd_acquire);
126 if (dbd_acquire_fn == NULL) {
127 log_error(APLOG_MARK,APLOG_ERR,0,s,"You must load mod_dbd to enable AuthDBD functions");
128 }
129
130 log_sql_register_driver(p,&log_sql_dbd_driver);
131 LOGSQL_REGISTER_RETURN;
132}
diff --git a/mod_log_sql_dbi.c b/mod_log_sql_dbi.c
index 8afd844..40a972b 100644
--- a/mod_log_sql_dbi.c
+++ b/mod_log_sql_dbi.c
@@ -90,7 +90,7 @@ static void log_sql_dbi_close(logsql_dbconnection *db)
90/* Routine to escape the 'dangerous' characters that would otherwise 90/* Routine to escape the 'dangerous' characters that would otherwise
91 * corrupt the INSERT string: ', \, and " 91 * corrupt the INSERT string: ', \, and "
92 */ 92 */
93static const char *log_sql_dbi_escape(const char *from_str, apr_pool_t *p, 93static const char *log_sql_dbi_escape(request_rec *r,const char *from_str, apr_pool_t *p,
94 logsql_dbconnection *db) 94 logsql_dbconnection *db)
95{ 95{
96 dbi_conn_rec *dblink = db->handle; 96 dbi_conn_rec *dblink = db->handle;
diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c
index 8202672..942c03a 100644
--- a/mod_log_sql_mysql.c
+++ b/mod_log_sql_mysql.c
@@ -74,7 +74,7 @@ static void log_sql_mysql_close(logsql_dbconnection *db)
74/* Routine to escape the 'dangerous' characters that would otherwise 74/* Routine to escape the 'dangerous' characters that would otherwise
75 * corrupt the INSERT string: ', \, and " 75 * corrupt the INSERT string: ', \, and "
76 */ 76 */
77static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p, 77static const char *log_sql_mysql_escape(request_rec *r, const char *from_str, apr_pool_t *p,
78 logsql_dbconnection *db) 78 logsql_dbconnection *db)
79{ 79{
80 /* Return "NULL" for empty strings */ 80 /* Return "NULL" for empty strings */