diff options
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r-- | mod_log_sql.c | 266 |
1 files changed, 149 insertions, 117 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c index 50c7964..faac51e 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id $ */ | 1 | /* $Id: mod_log_sql.c,v 1.17 2004/03/02 05:34:50 urkle Exp $ */ |
2 | /* --------* | 2 | /* --------* |
3 | * DEFINES * | 3 | * DEFINES * |
4 | * --------*/ | 4 | * --------*/ |
@@ -61,7 +61,6 @@ typedef struct { | |||
61 | int createtables; | 61 | int createtables; |
62 | int forcepreserve; | 62 | int forcepreserve; |
63 | char *machid; | 63 | char *machid; |
64 | apr_table_t *dbparams; | ||
65 | logsql_dbconnection db; | 64 | logsql_dbconnection db; |
66 | } global_config_t; | 65 | } global_config_t; |
67 | 66 | ||
@@ -147,56 +146,28 @@ LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p, | |||
147 | # include "functions20.h" | 146 | # include "functions20.h" |
148 | #endif | 147 | #endif |
149 | 148 | ||
150 | /* Routine to escape the 'dangerous' characters that would otherwise | 149 | static logsql_opendb_ret log_sql_opendb_link(server_rec* s) |
151 | * corrupt the INSERT string: ', \, and " | ||
152 | */ | ||
153 | static const char *escape_query(const char *from_str, apr_pool_t *p) | ||
154 | { | ||
155 | if (!from_str) | ||
156 | return NULL; | ||
157 | else { | ||
158 | char *to_str; | ||
159 | unsigned long length = strlen(from_str); | ||
160 | unsigned long retval; | ||
161 | |||
162 | /* Pre-allocate a new string that could hold twice the original, which would only | ||
163 | * happen if the whole original string was 'dangerous' characters. | ||
164 | */ | ||
165 | to_str = (char *) apr_palloc(p, length * 2 + 1); | ||
166 | if (!to_str) { | ||
167 | return from_str; | ||
168 | } | ||
169 | |||
170 | if (!global_config.db.connected) { | ||
171 | /* Well, I would have liked to use the current database charset. mysql is | ||
172 | * unavailable, however, so I fall back to the slightly less respectful | ||
173 | * mysql_escape_string() function that uses the default charset. | ||
174 | */ | ||
175 | retval = mysql_escape_string(to_str, from_str, length); | ||
176 | } else { | ||
177 | /* MySQL is available, so I'll go ahead and respect the current charset when | ||
178 | * I perform the escape. | ||
179 | */ | ||
180 | retval = mysql_real_escape_string(global_config.db.handle, to_str, from_str, length); | ||
181 | } | ||
182 | |||
183 | if (retval) | ||
184 | return to_str; | ||
185 | else | ||
186 | return from_str; | ||
187 | } | ||
188 | } | ||
189 | |||
190 | static logsql_opendb open_logdb_link(server_rec* s) | ||
191 | { | 150 | { |
151 | logsql_opendb_ret result; | ||
192 | if (global_config.forcepreserve) | 152 | if (global_config.forcepreserve) |
153 | global_config.db.connected = 1; | ||
193 | return LOGSQL_OPENDB_PRESERVE; | 154 | return LOGSQL_OPENDB_PRESERVE; |
194 | 155 | ||
195 | if (global_config.db.connected) | 156 | if (global_config.db.connected) |
196 | return LOGSQL_OPENDB_ALREADY; | 157 | return LOGSQL_OPENDB_ALREADY; |
197 | 158 | /* database | |
198 | if ((global_config.dbname) && (global_config.dbhost) && (global_config.dbuser) && (global_config.dbpwd)) { | 159 | host |
199 | log_sql_mysql_connect(); | 160 | user |
161 | passwd | ||
162 | */ | ||
163 | if (global_config.db.parms) { | ||
164 | result = log_sql_mysql_connect(s, &global_config.db); | ||
165 | if (result==LOGSQL_OPENDB_FAIL) { | ||
166 | global_config.db.connected = 0; | ||
167 | } else { | ||
168 | global_config.db.connected = 1; | ||
169 | } | ||
170 | return result; | ||
200 | } else { | 171 | } else { |
201 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); | 172 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); |
202 | return LOGSQL_OPENDB_FAIL; | 173 | return LOGSQL_OPENDB_FAIL; |
@@ -323,21 +294,24 @@ static const char *set_server_nmv_string_slot(cmd_parms *parms, | |||
323 | } | 294 | } |
324 | 295 | ||
325 | /* Set a DB connection parameter */ | 296 | /* Set a DB connection parameter */ |
326 | static void set_dbparam(apr_pool_t *p, const char *key, | 297 | static const char *set_dbparam(cmd_parms *cmd, |
327 | const char *val); | 298 | void *struct_ptr, |
299 | const char *key, | ||
300 | const char *val) | ||
328 | { | 301 | { |
329 | if (!global_config.dbparams) { | 302 | if (!global_config.db.parms) { |
330 | global_config.dbparams = apr_table_make(p,5); | 303 | global_config.db.parms = apr_table_make(cmd->pool,5); |
331 | } | 304 | } |
332 | apr_table_set(global_config.dbparams,key,val); | 305 | apr_table_set(global_config.db.parms,key,val); |
306 | return NULL; | ||
333 | } | 307 | } |
334 | 308 | ||
335 | static const char *set_dbparam_slot(cmd_params *cmd, | 309 | static const char *set_dbparam_slot(cmd_parms *cmd, |
336 | void *struct_ptr, | 310 | void *struct_ptr, |
337 | const char *arg) | 311 | const char *arg) |
338 | { | 312 | { |
339 | const char *param = (char *)cmd->info; | 313 | const char *param = (char *)cmd->info; |
340 | set_dbparam(cmd->pool,param,arg); | 314 | set_dbparam(cmd,NULL,param,arg); |
341 | return NULL; | 315 | return NULL; |
342 | } | 316 | } |
343 | 317 | ||
@@ -346,14 +320,13 @@ static const char *set_log_sql_info(cmd_parms *cmd, void *dummy, | |||
346 | const char *host, const char *user, const char *pwd) | 320 | const char *host, const char *user, const char *pwd) |
347 | { | 321 | { |
348 | if (*host != '.') { | 322 | if (*host != '.') { |
349 | set_db_param_slot(cmd->pool, "host", host); | 323 | set_dbparam(cmd, NULL, "host", host); |
350 | } | 324 | } |
351 | if (*user != '.') { | 325 | if (*user != '.') { |
352 | set_db_param_slot(cmd->pool, "user", user); | 326 | set_dbparam(cmd, NULL, "user", user); |
353 | global_config.dbuser = apr_pstrdup(cmd->pool,user); | ||
354 | } | 327 | } |
355 | if (*pwd != '.') { | 328 | if (*pwd != '.') { |
356 | set_db_param_slot(cmd->pool, "passwd", pwd); | 329 | set_dbparam(cmd, NULL, "passwd", pwd); |
357 | } | 330 | } |
358 | return NULL; | 331 | return NULL; |
359 | } | 332 | } |
@@ -373,13 +346,6 @@ static const char *add_server_string_slot(cmd_parms *cmd, | |||
373 | return NULL; | 346 | return NULL; |
374 | } | 347 | } |
375 | 348 | ||
376 | static const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, const char *arg) | ||
377 | { | ||
378 | global_config.tcpport = (unsigned int)atoi(arg); | ||
379 | |||
380 | return NULL; | ||
381 | } | ||
382 | |||
383 | /*------------------------------------------------------------* | 349 | /*------------------------------------------------------------* |
384 | * Apache-specific hooks into the module code * | 350 | * Apache-specific hooks into the module code * |
385 | * that are defined in the array 'mysql_lgog_module' (at EOF) * | 351 | * that are defined in the array 'mysql_lgog_module' (at EOF) * |
@@ -388,13 +354,13 @@ static const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, const cha | |||
388 | #if defined(WITH_APACHE20) | 354 | #if defined(WITH_APACHE20) |
389 | static apr_status_t log_sql_close_link(void *data) | 355 | static apr_status_t log_sql_close_link(void *data) |
390 | { | 356 | { |
391 | mysql_close(global_config.server_p); | 357 | log_sql_mysql_close(&global_config.db); |
392 | return APR_SUCCESS; | 358 | return APR_SUCCESS; |
393 | } | 359 | } |
394 | #elif defined(WITH_APACHE13) | 360 | #elif defined(WITH_APACHE13) |
395 | static void log_sql_child_exit(server_rec *s, apr_pool_t *p) | 361 | static void log_sql_child_exit(server_rec *s, apr_pool_t *p) |
396 | { | 362 | { |
397 | mysql_close(global_config.server_p); | 363 | log_sql_mysql_close(&global_config.db); |
398 | } | 364 | } |
399 | #endif | 365 | #endif |
400 | 366 | ||
@@ -410,9 +376,9 @@ static int log_sql_open(apr_pool_t *pc, apr_pool_t *p, apr_pool_t *pt, server_re | |||
410 | static void log_sql_child_init(server_rec *s, apr_pool_t *p) | 376 | static void log_sql_child_init(server_rec *s, apr_pool_t *p) |
411 | #endif | 377 | #endif |
412 | { | 378 | { |
413 | logsql_opendb retval; | 379 | logsql_opendb_ret retval; |
414 | /* Open a link to the database */ | 380 | /* Open a link to the database */ |
415 | retval = open_logdb_link(s); | 381 | retval = log_sql_opendb_link(s); |
416 | switch (retval) { | 382 | switch (retval) { |
417 | case LOGSQL_OPENDB_FAIL: | 383 | case LOGSQL_OPENDB_FAIL: |
418 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); | 384 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); |
@@ -438,10 +404,10 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p) | |||
438 | #endif | 404 | #endif |
439 | { | 405 | { |
440 | /* Initialize Global configuration */ | 406 | /* Initialize Global configuration */ |
441 | if (!global_config.socketfile) | 407 | if (!apr_table_get(global_config.db.parms,"socketfile")) |
442 | global_config.socketfile = "/tmp/mysql.sock"; | 408 | apr_table_setn(global_config.db.parms,"socketfile","/tmp/mysql.sock"); |
443 | if (!global_config.tcpport) | 409 | if (!apr_table_get(global_config.db.parms,"tcpport")) |
444 | global_config.tcpport = 3306; | 410 | apr_table_setn(global_config.db.parms,"tcpport","3306"); |
445 | 411 | ||
446 | /* TODO: Add local_address, remote_address, server_name, connection_status */ | 412 | /* TODO: Add local_address, remote_address, server_name, connection_status */ |
447 | /* Register handlers */ | 413 | /* Register handlers */ |
@@ -481,11 +447,88 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p) | |||
481 | * Parms: request record, table type, table name, and the full SQL command | 447 | * Parms: request record, table type, table name, and the full SQL command |
482 | */ | 448 | */ |
483 | 449 | ||
484 | static void safe_sql_insert(request_rec *r, logsql_tabletype table_type, | 450 | static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_type, |
485 | const char *table_name, const char *sql) { | 451 | const char *table_name, const char *query) { |
486 | int result; | 452 | |
487 | if (!global_config.connected) { | 453 | logsql_query_ret result; |
454 | logsql_state *cls = ap_get_module_config(r->server->module_config, | ||
455 | &log_sql_module); | ||
456 | |||
457 | if (!global_config.db.connected) { | ||
458 | /* preserve query */ | ||
459 | return LOGSQL_QUERY_NOLINK; | ||
460 | } | ||
461 | |||
462 | result = log_sql_mysql_query(r,&global_config.db,query); | ||
463 | |||
464 | /* If we ran the query and it returned an error, try to be robust. | ||
465 | * (After all, the module thought it had a valid mysql_log connection but the query | ||
466 | * could have failed for a number of reasons, so we have to be extra-safe and check.) */ | ||
467 | switch (result) { | ||
468 | case LOGSQL_QUERY_SUCCESS: | ||
469 | return LOGSQL_QUERY_SUCCESS; | ||
470 | case LOGSQL_QUERY_NOLINK: | ||
471 | return LOGSQL_QUERY_FAIL; | ||
472 | /* TODO: What do we do here */ | ||
473 | case LOGSQL_QUERY_FAIL: | ||
474 | log_sql_mysql_close(&global_config.db); | ||
475 | global_config.db.connected = 0; | ||
476 | /* re-open the connection and try again */ | ||
477 | if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) { | ||
478 | log_error(APLOG_MARK,APLOG_ERR,r->server,"db reconnect successful"); | ||
479 | result = log_sql_mysql_query(r,&global_config.db,query); | ||
480 | if (result == LOGSQL_QUERY_SUCCESS) { | ||
481 | return LOGSQL_QUERY_SUCCESS; | ||
482 | } else { | ||
483 | log_error(APLOG_MARK,APLOG_ERR,r->server,"second attempt failed"); | ||
484 | preserve_entry(r, query); | ||
485 | return LOGSQL_QUERY_PRESERVED; | ||
486 | } | ||
487 | } else { | ||
488 | log_error(APLOG_MARK,APLOG_ERR,r->server,"reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); | ||
489 | log_error(APLOG_MARK,APLOG_ERR,r->server,"log entries are being preserved in %s",cls->preserve_file); | ||
490 | preserve_entry(r, query); | ||
491 | return LOGSQL_QUERY_PRESERVED; | ||
492 | } | ||
493 | break; | ||
494 | case LOGSQL_QUERY_NOTABLE: | ||
495 | if (global_config.createtables) { | ||
496 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
497 | "table doesn't exist...creating now"); | ||
498 | if ((result = log_sql_mysql_create(r, &global_config.db, table_type, | ||
499 | table_name))!=LOGSQL_TABLE_SUCCESS) { | ||
500 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
501 | "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); | ||
502 | preserve_entry(r, query); | ||
503 | return LOGSQL_QUERY_PRESERVED; | ||
504 | } else { | ||
505 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
506 | "tables successfully created - retrying query"); | ||
507 | if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) { | ||
508 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
509 | "giving up, preserving query"); | ||
510 | preserve_entry(r, query); | ||
511 | return LOGSQL_QUERY_PRESERVED; | ||
512 | } else { | ||
513 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
514 | "query successful after table creation"); | ||
515 | return LOGSQL_QUERY_SUCCESS; | ||
516 | } | ||
517 | } | ||
518 | } else { | ||
519 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
520 | "table doesn't exist, creation denied by configuration, preserving query"); | ||
521 | preserve_entry(r, query); | ||
522 | return LOGSQL_QUERY_PRESERVED; | ||
523 | } | ||
524 | break; | ||
525 | default: | ||
526 | log_error(APLOG_MARK,APLOG_ERR,r->server, | ||
527 | "Invalid return code from mog_log_query"); | ||
528 | return LOGSQL_QUERY_FAIL; | ||
529 | break; | ||
488 | } | 530 | } |
531 | return LOGSQL_QUERY_FAIL; | ||
489 | } | 532 | } |
490 | 533 | ||
491 | /* This function gets called to create a per-server configuration | 534 | /* This function gets called to create a per-server configuration |
@@ -726,7 +769,7 @@ static int log_sql_transaction(request_rec *orig) | |||
726 | item->sql_field_name, NULL); | 769 | item->sql_field_name, NULL); |
727 | values = apr_pstrcat(r->pool, values, (i ? "," : ""), | 770 | values = apr_pstrcat(r->pool, values, (i ? "," : ""), |
728 | (item->string_contents ? "'" : ""), | 771 | (item->string_contents ? "'" : ""), |
729 | escape_query(formatted_item, r->pool), | 772 | log_sql_mysql_escape(formatted_item, r->pool,&global_config.db), |
730 | (item->string_contents ? "'" : ""), NULL); | 773 | (item->string_contents ? "'" : ""), NULL); |
731 | } | 774 | } |
732 | 775 | ||
@@ -743,9 +786,9 @@ static int log_sql_transaction(request_rec *orig) | |||
743 | "('", | 786 | "('", |
744 | unique_id, | 787 | unique_id, |
745 | "','", | 788 | "','", |
746 | escape_query(*ptrptr, r->pool), | 789 | log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), |
747 | "','", | 790 | "','", |
748 | escape_query(theitem, r->pool), | 791 | log_sql_mysql_escape(theitem, r->pool,&global_config.db), |
749 | "')", | 792 | "')", |
750 | NULL); | 793 | NULL); |
751 | i++; | 794 | i++; |
@@ -753,7 +796,7 @@ static int log_sql_transaction(request_rec *orig) | |||
753 | } | 796 | } |
754 | if ( itemsets != "" ) { | 797 | if ( itemsets != "" ) { |
755 | note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", | 798 | note_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", |
756 | global_config.insertdelayed?"delayed":"", notes_tablename, itemsets); | 799 | /*global_config.insertdelayed?"delayed":*/"", notes_tablename, itemsets); |
757 | 800 | ||
758 | #ifdef DEBUG | 801 | #ifdef DEBUG |
759 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); | 802 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); |
@@ -773,9 +816,9 @@ static int log_sql_transaction(request_rec *orig) | |||
773 | "('", | 816 | "('", |
774 | unique_id, | 817 | unique_id, |
775 | "','", | 818 | "','", |
776 | escape_query(*ptrptr, r->pool), | 819 | log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), |
777 | "','", | 820 | "','", |
778 | escape_query(theitem, r->pool), | 821 | log_sql_mysql_escape(theitem, r->pool,&global_config.db), |
779 | "')", | 822 | "')", |
780 | NULL); | 823 | NULL); |
781 | i++; | 824 | i++; |
@@ -783,11 +826,9 @@ static int log_sql_transaction(request_rec *orig) | |||
783 | } | 826 | } |
784 | if ( itemsets != "" ) { | 827 | if ( itemsets != "" ) { |
785 | hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", | 828 | hout_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", |
786 | global_config.insertdelayed?"delayed":"", hout_tablename, itemsets); | 829 | /*global_config.insertdelayed?"delayed":*/"", hout_tablename, itemsets); |
787 | 830 | ||
788 | #ifdef DEBUG | 831 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); |
789 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); | ||
790 | #endif | ||
791 | } | 832 | } |
792 | 833 | ||
793 | 834 | ||
@@ -804,9 +845,9 @@ static int log_sql_transaction(request_rec *orig) | |||
804 | "('", | 845 | "('", |
805 | unique_id, | 846 | unique_id, |
806 | "','", | 847 | "','", |
807 | escape_query(*ptrptr, r->pool), | 848 | log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), |
808 | "','", | 849 | "','", |
809 | escape_query(theitem, r->pool), | 850 | log_sql_mysql_escape(theitem, r->pool,&global_config.db), |
810 | "')", | 851 | "')", |
811 | NULL); | 852 | NULL); |
812 | i++; | 853 | i++; |
@@ -814,11 +855,9 @@ static int log_sql_transaction(request_rec *orig) | |||
814 | } | 855 | } |
815 | if ( itemsets != "" ) { | 856 | if ( itemsets != "" ) { |
816 | hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", | 857 | hin_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", |
817 | global_config.insertdelayed?"delayed":"", hin_tablename, itemsets); | 858 | /*global_config.insertdelayed?"delayed":*/"", hin_tablename, itemsets); |
818 | 859 | ||
819 | #ifdef DEBUG | 860 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); |
820 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); | ||
821 | #endif | ||
822 | } | 861 | } |
823 | 862 | ||
824 | 863 | ||
@@ -835,9 +874,9 @@ static int log_sql_transaction(request_rec *orig) | |||
835 | "('", | 874 | "('", |
836 | unique_id, | 875 | unique_id, |
837 | "','", | 876 | "','", |
838 | escape_query(*ptrptr, r->pool), | 877 | log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), |
839 | "','", | 878 | "','", |
840 | escape_query(theitem, r->pool), | 879 | log_sql_mysql_escape(theitem, r->pool,&global_config.db), |
841 | "')", | 880 | "')", |
842 | NULL); | 881 | NULL); |
843 | i++; | 882 | i++; |
@@ -846,29 +885,23 @@ static int log_sql_transaction(request_rec *orig) | |||
846 | } | 885 | } |
847 | if ( itemsets != "" ) { | 886 | if ( itemsets != "" ) { |
848 | cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", | 887 | cookie_query = apr_psprintf(r->pool, "insert %s into `%s` (id, item, val) values %s", |
849 | global_config.insertdelayed?"delayed":"", cookie_tablename, itemsets); | 888 | /*global_config.insertdelayed?"delayed":*/"", cookie_tablename, itemsets); |
850 | 889 | ||
851 | #ifdef DEBUG | 890 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); |
852 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); | ||
853 | #endif | ||
854 | } | 891 | } |
855 | 892 | ||
856 | 893 | ||
857 | /* Set up the actual INSERT statement */ | 894 | /* Set up the actual INSERT statement */ |
858 | access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)", | 895 | access_query = apr_psprintf(r->pool, "insert %s into `%s` (%s) values (%s)", |
859 | global_config.insertdelayed?"delayed":"", transfer_tablename, fields, values); | 896 | /*global_config.insertdelayed?"delayed":*/"", transfer_tablename, fields, values); |
860 | 897 | ||
861 | #ifdef DEBUG | 898 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); |
862 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); | ||
863 | #endif | ||
864 | 899 | ||
865 | /* If the person activated force-preserve, go ahead and push all the entries | 900 | /* If the person activated force-preserve, go ahead and push all the entries |
866 | * into the preserve file, then return. | 901 | * into the preserve file, then return. |
867 | */ | 902 | */ |
868 | if (global_config.forcepreserve) { | 903 | if (global_config.forcepreserve) { |
869 | #ifdef DEBUG | 904 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); |
870 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); | ||
871 | #endif | ||
872 | preserve_entry(orig, access_query); | 905 | preserve_entry(orig, access_query); |
873 | if ( note_query != NULL ) | 906 | if ( note_query != NULL ) |
874 | preserve_entry(orig, note_query); | 907 | preserve_entry(orig, note_query); |
@@ -882,12 +915,12 @@ static int log_sql_transaction(request_rec *orig) | |||
882 | } | 915 | } |
883 | 916 | ||
884 | /* How's our mysql link integrity? */ | 917 | /* How's our mysql link integrity? */ |
885 | if (global_config.server_p == NULL) { | 918 | if (!global_config.db.connected) { |
886 | 919 | ||
887 | /* Make a try to establish the link */ | 920 | /* Make a try to establish the link */ |
888 | open_logdb_link(r->server); | 921 | log_sql_opendb_link(r->server); |
889 | 922 | ||
890 | if (global_config.server_p == NULL) { | 923 | if (!global_config.db.connected) { |
891 | /* Unable to re-establish a DB link, so assume that it's really | 924 | /* Unable to re-establish a DB link, so assume that it's really |
892 | * gone and send the entry to the preserve file instead. | 925 | * gone and send the entry to the preserve file instead. |
893 | * This short-circuits safe_sql_query() during a db outage and therefore | 926 | * This short-circuits safe_sql_query() during a db outage and therefore |
@@ -915,24 +948,20 @@ static int log_sql_transaction(request_rec *orig) | |||
915 | /* ---> i.e. we have a good MySQL connection. <--- */ | 948 | /* ---> i.e. we have a good MySQL connection. <--- */ |
916 | 949 | ||
917 | /* Make the access-table insert */ | 950 | /* Make the access-table insert */ |
918 | if (safe_create_tables(orig, LOGSQL_TABLE_ACCESS, transfer_tablename)==APR_SUCCESS) { | 951 | safe_sql_insert(orig,LOGSQL_TABLE_ACCESS,transfer_tablename,access_query); |
919 | safe_sql_query(orig, access_query); | ||
920 | } else { | ||
921 | preserve_entry(orig, access_query); | ||
922 | } | ||
923 | 952 | ||
924 | /* Log the optional notes, headers, etc. */ | 953 | /* Log the optional notes, headers, etc. */ |
925 | if (note_query) | 954 | if (note_query) |
926 | safe_sql_query(orig, note_query); | 955 | safe_sql_insert(orig, LOGSQL_TABLE_NOTES,notes_tablename,note_query); |
927 | 956 | ||
928 | if (hout_query) | 957 | if (hout_query) |
929 | safe_sql_query(orig, hout_query); | 958 | safe_sql_insert(orig, LOGSQL_TABLE_HEADERSOUT,hout_tablename,hout_query); |
930 | 959 | ||
931 | if (hin_query) | 960 | if (hin_query) |
932 | safe_sql_query(orig, hin_query); | 961 | safe_sql_insert(orig, LOGSQL_TABLE_HEADERSIN,hin_tablename,hin_query); |
933 | 962 | ||
934 | if (cookie_query) | 963 | if (cookie_query) |
935 | safe_sql_query(orig, cookie_query); | 964 | safe_sql_insert(orig, LOGSQL_TABLE_COOKIES,cookie_tablename,cookie_query); |
936 | 965 | ||
937 | return OK; | 966 | return OK; |
938 | } | 967 | } |
@@ -1027,6 +1056,9 @@ static const command_rec log_sql_cmds[] = { | |||
1027 | AP_INIT_TAKE3("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF, | 1056 | AP_INIT_TAKE3("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF, |
1028 | "The database host, user-id and password for logging") | 1057 | "The database host, user-id and password for logging") |
1029 | , | 1058 | , |
1059 | AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF, | ||
1060 | "First argument is the DB parameter, second is the value to assign") | ||
1061 | , | ||
1030 | AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot, | 1062 | AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot, |
1031 | (void *)"database", RSRC_CONF, | 1063 | (void *)"database", RSRC_CONF, |
1032 | "The name of the database database for logging") | 1064 | "The name of the database database for logging") |