summaryrefslogtreecommitdiffstatsabout
path: root/mod_log_sql.c
diff options
context:
space:
mode:
authorChristopher Powell <chris@grubbybaby.com>2002-11-27 07:13:59 (GMT)
committer Christopher Powell <chris@grubbybaby.com>2002-11-27 07:13:59 (GMT)
commitef6cec547cbb21caa7204095ee914cba89f6247b (patch)
tree75b78ac843e03ff0632aa2b82b8e5d0cc2fc9d9f /mod_log_sql.c
parentc00607cbde2fc719bfc1af4e9c58a9eb4eccf691 (diff)
Further Makefile reorg/cleanup, a new option to support delayed inserts
with accompanying documentation.
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r--mod_log_sql.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 6d3110c..3fc7ace 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,11 +1,11 @@
1/* $Id: mod_log_sql.c,v 1.18 2002/11/14 22:52:54 helios Exp $ */ 1/* $Id: mod_log_sql.c,v 1.19 2002/11/27 07:13:58 helios Exp $ */
2 2
3/* --------* 3/* --------*
4 * DEFINES * 4 * DEFINES *
5 * --------*/ 5 * --------*/
6 6
7/* The enduser may wish to modify this */ 7/* The enduser may wish to modify this */
8#undef DEBUG 8#define DEBUG
9 9
10/* The enduser won't modify these */ 10/* The enduser won't modify these */
11#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away") 11#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away")
@@ -19,6 +19,7 @@
19 * ---------*/ 19 * ---------*/
20#include <time.h> 20#include <time.h>
21#include <stdio.h> 21#include <stdio.h>
22#include <stdlib.h>
22#include "httpd.h" 23#include "httpd.h"
23#include "http_config.h" 24#include "http_config.h"
24#include "http_log.h" 25#include "http_log.h"
@@ -57,6 +58,11 @@ char *db_pwd = NULL;
57char *mach_id = NULL; 58char *mach_id = NULL;
58char *socket_file = "/tmp/mysql.sock"; 59char *socket_file = "/tmp/mysql.sock";
59unsigned int tcp_port = 3306; 60unsigned int tcp_port = 3306;
61#ifdef WANT_DELAYED_MYSQL_INSERT
62 char *insert_stmt = "insert delayed into ";
63#else
64 char *insert_stmt = "insert into ";
65#endif
60 66
61typedef const char *(*item_key_func) (request_rec *, char *); 67typedef const char *(*item_key_func) (request_rec *, char *);
62 68
@@ -601,7 +607,7 @@ int open_logdb_link(server_rec* s)
601 if (force_preserve) 607 if (force_preserve)
602 return 3; 608 return 3;
603 609
604 if (mysql_log != NULL) 610 if (mysql_log)
605 return 2; 611 return 2;
606 612
607 if (db_name) { 613 if (db_name) {
@@ -609,6 +615,10 @@ int open_logdb_link(server_rec* s)
609 mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, tcp_port, socket_file, 0); 615 mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, tcp_port, socket_file, 0);
610 616
611 if (mysql_log) { 617 if (mysql_log) {
618 #ifdef DEBUG
619 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'",
620 db_host, tcp_port, db_name, db_user, socket_file);
621 #endif
612 return 1; 622 return 1;
613 } else { 623 } else {
614 #ifdef DEBUG 624 #ifdef DEBUG
@@ -623,28 +633,10 @@ int open_logdb_link(server_rec* s)
623 return 0; 633 return 0;
624} 634}
625 635
626#ifdef DEBUG
627static int trace(void *data, const char *key, const char *val)
628{
629 FILE *fp;
630 request_rec *r = (request_rec *)data;
631
632 fp = pfopen(r->pool, "/tmp/trace", "a");
633
634 if (fp) {
635 fprintf(fp, "Field '%s' == '%s'\n", key, val);
636 }
637
638 pfclose(r->pool, fp);
639
640 return TRUE;
641}
642#endif
643
644const char *extract_table(void *data, const char *key, const char *val) 636const char *extract_table(void *data, const char *key, const char *val)
645{ 637{
646 request_rec *r = (request_rec *)data; 638 request_rec *r = (request_rec *)data;
647 639
648 return ap_pstrcat(r->pool, key, " = ", val, " ", NULL); 640 return ap_pstrcat(r->pool, key, " = ", val, " ", NULL);
649} 641}
650 642
@@ -1409,7 +1401,7 @@ int log_sql_transaction(request_rec *orig)
1409 } 1401 }
1410 } 1402 }
1411 if ( itemsets != "" ) { 1403 if ( itemsets != "" ) {
1412 note_query = ap_pstrcat(r->pool, "insert into `", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL); 1404 note_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL);
1413 #ifdef DEBUG 1405 #ifdef DEBUG
1414 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query); 1406 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query);
1415 #endif 1407 #endif
@@ -1437,7 +1429,7 @@ int log_sql_transaction(request_rec *orig)
1437 } 1429 }
1438 } 1430 }
1439 if ( itemsets != "" ) { 1431 if ( itemsets != "" ) {
1440 hout_query = ap_pstrcat(r->pool, "insert into `", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL); 1432 hout_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL);
1441 #ifdef DEBUG 1433 #ifdef DEBUG
1442 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_out string: %s", hout_query); 1434 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_out string: %s", hout_query);
1443 #endif 1435 #endif
@@ -1466,7 +1458,7 @@ int log_sql_transaction(request_rec *orig)
1466 } 1458 }
1467 } 1459 }
1468 if ( itemsets != "" ) { 1460 if ( itemsets != "" ) {
1469 hin_query = ap_pstrcat(r->pool, "insert into `", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL); 1461 hin_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL);
1470 #ifdef DEBUG 1462 #ifdef DEBUG
1471 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_in string: %s", hin_query); 1463 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_in string: %s", hin_query);
1472 #endif 1464 #endif
@@ -1496,7 +1488,7 @@ int log_sql_transaction(request_rec *orig)
1496 1488
1497 } 1489 }
1498 if ( itemsets != "" ) { 1490 if ( itemsets != "" ) {
1499 cookie_query = ap_pstrcat(r->pool, "insert into `", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL); 1491 cookie_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL);
1500 #ifdef DEBUG 1492 #ifdef DEBUG
1501 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: cookie string: %s", cookie_query); 1493 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: cookie string: %s", cookie_query);
1502 #endif 1494 #endif
@@ -1504,7 +1496,7 @@ int log_sql_transaction(request_rec *orig)
1504 1496
1505 1497
1506 /* Set up the actual INSERT statement */ 1498 /* Set up the actual INSERT statement */
1507 access_query = ap_pstrcat(r->pool, "insert into `", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL); 1499 access_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL);
1508 1500
1509 #ifdef DEBUG 1501 #ifdef DEBUG
1510 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"mod_log_sql: access string: %s", access_query); 1502 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"mod_log_sql: access string: %s", access_query);