summaryrefslogtreecommitdiffstats
path: root/mod_log_sql.c
diff options
context:
space:
mode:
authorGravatar Christopher Powell 2002-05-16 21:35:12 +0000
committerGravatar Christopher Powell 2002-05-16 21:35:12 +0000
commit29329b3e7c68e6af2370968d7900daffa63adb93 (patch)
tree3ccbca2b5995827151c84e4810dcdb4cfe4c64e1 /mod_log_sql.c
parent7bac244dcd4356314c37a469b957d9b94cddaba6 (diff)
Further changes on the way to 1.17, big one was the segfault fix.
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r--mod_log_sql.c304
1 files changed, 153 insertions, 151 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 84c6115..6726163 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,4 +1,4 @@
1/* $Id: mod_log_sql.c,v 1.12 2002/05/14 21:47:15 helios Exp $ */ 1/* $Id: mod_log_sql.c,v 1.13 2002/05/16 21:35:12 helios Exp $ */
2 2
3/* --------* 3/* --------*
4 * DEFINES * 4 * DEFINES *
@@ -76,7 +76,7 @@ typedef struct {
76 char *transfer_log_format; 76 char *transfer_log_format;
77 char *preserve_file; 77 char *preserve_file;
78 char *cookie_name; 78 char *cookie_name;
79} log_mysql_state; 79} log_sql_state;
80 80
81 81
82/* -----------------* 82/* -----------------*
@@ -322,7 +322,7 @@ static const char *extract_cookie(request_rec *r, char *a)
322 char *isvalid; 322 char *isvalid;
323 char *cookiebuf; 323 char *cookiebuf;
324 324
325 log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); 325 log_sql_state *cls = get_module_config(r->server->module_config, &mysql_log_module);
326 326
327 if (cls->cookie_name != NULL) { 327 if (cls->cookie_name != NULL) {
328 #ifdef DEBUG 328 #ifdef DEBUG
@@ -423,13 +423,13 @@ static const char *extract_unique_id(request_rec *r, char *a)
423 423
424 424
425 425
426struct log_mysql_item_list { 426struct log_sql_item_list {
427 char ch; /* its letter code */ 427 char ch; /* its letter code */
428 item_key_func func; /* its extraction function */ 428 item_key_func func; /* its extraction function */
429 const char *sql_field_name; /* its column in SQL */ 429 const char *sql_field_name; /* its column in SQL */
430 int want_orig_default; /* if it requires the original request prior to internal redirection */ 430 int want_orig_default; /* if it requires the original request prior to internal redirection */
431 int string_contents; /* if it returns a string */ 431 int string_contents; /* if it returns a string */
432 } log_mysql_item_keys[] = { 432 } log_sql_item_keys[] = {
433 433
434 { 'A', extract_agent, "agent", 1, 1 }, 434 { 'A', extract_agent, "agent", 1, 1 },
435 { 'b', extract_bytes_sent, "bytes_sent", 0, 0 }, 435 { 'b', extract_bytes_sent, "bytes_sent", 0, 0 },
@@ -553,11 +553,11 @@ const char *extract_table(void *data, const char *key, const char *val)
553void preserve_entry(request_rec *r, const char *query) 553void preserve_entry(request_rec *r, const char *query)
554{ 554{
555 FILE *fp; 555 FILE *fp;
556 log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); 556 log_sql_state *cls = get_module_config(r->server->module_config, &mysql_log_module);
557 557
558 fp = pfopen(r->pool, cls->preserve_file, "a"); 558 fp = pfopen(r->pool, cls->preserve_file, "a");
559 if (fp == NULL) 559 if (fp == NULL)
560 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempted append of local offline file but failed."); 560 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: attempted append of local preserve file but failed.");
561 else { 561 else {
562 fprintf(fp,"%s;\n", query); 562 fprintf(fp,"%s;\n", query);
563 pfclose(r->pool, fp); 563 pfclose(r->pool, fp);
@@ -565,7 +565,7 @@ void preserve_entry(request_rec *r, const char *query)
565} 565}
566 566
567/*-----------------------------------------------------*/ 567/*-----------------------------------------------------*/
568/* safe_mysql_query: perform a database insert with */ 568/* safe_mysql_query: perform a database query with */
569/* a degree of safety and error checking. */ 569/* a degree of safety and error checking. */
570/* */ 570/* */
571/* Parms: request record, SQL insert statement */ 571/* Parms: request record, SQL insert statement */
@@ -577,7 +577,6 @@ int safe_mysql_query(request_rec *r, const char *query)
577 int retval; 577 int retval;
578 struct timespec delay, remainder; 578 struct timespec delay, remainder;
579 int ret; 579 int ret;
580 char *str;
581 void (*handler) (int); 580 void (*handler) (int);
582 581
583 582
@@ -585,53 +584,54 @@ int safe_mysql_query(request_rec *r, const char *query)
585 handler = signal(SIGPIPE, SIG_IGN); 584 handler = signal(SIGPIPE, SIG_IGN);
586 585
587 /* First attempt for the query */ 586 /* First attempt for the query */
588 retval = mysql_query(mysql_log, query); 587 if (mysql_log != NULL)
589 588 retval = mysql_query(mysql_log, query);
589 else
590 return 1;
591
590 /* If we ran the query and it returned an error, try to be graceful. 592 /* If we ran the query and it returned an error, try to be graceful.
591 * We only reach this point if the module thinks it has a valid connection to the 593 * (The module thought it had a valid mysql_log connection but the query
592 * database (i.e. mysql_log is non-null). But that connection could go sour 594 * might have failed, so we have to check.)
593 * at any time, hence the check. */ 595 */
594 if ( retval != 0 ) 596 if ( retval != 0 )
595 { 597 {
596 log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); 598 log_sql_state *cls = get_module_config(r->server->module_config, &mysql_log_module);
597 599
598 /* Something went wrong, so start by trying to restart the db link. */ 600 /* Something went wrong, so start by trying to restart the db link. */
599 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempting reconnect because API said: %s", mysql_error(mysql_log)); 601 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: first attempt failed, API said: %s", MYSQL_ERROR(mysql_log));
600 602
601 mysql_log = NULL; 603 mysql_log = NULL;
602 open_logdb_link(); 604 open_logdb_link();
603 605
604 if (mysql_log == NULL) { /* still unable to link */ 606 if (mysql_log == NULL) { /* still unable to link */
605 signal(SIGPIPE, handler); 607 signal(SIGPIPE, handler);
606 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"httpd child reconnect failed, unable to reach database. SQL logging stopped until an httpd child regains a db connection."); 608 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection.");
607 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"log entries are being preserved in %s", cls->preserve_file); 609 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file);
608 preserve_entry(r, query); 610 preserve_entry(r, query);
609 return retval; 611 return retval;
610 } else { 612 } else {
611 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"reconnect successful."); 613 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: reconnect successful");
612 } 614 }
613
614 /* Attempt a single re-try... First sleep for a tiny amount of time. */
615 delay.tv_sec = 0;
616 delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */
617 ret = nanosleep(&delay, &remainder);
618 if (ret && errno != EINTR)
619 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"nanosleep unsuccessful.");
620
621 /* Now make our second attempt */
622 retval = mysql_query(mysql_log,query);
623
624 /* If this one also failed, log that and append to our local offline file */
625 if ( retval != 0 )
626 {
627 str = ap_pstrcat(r->pool, "delayed insert attempt failed, API said: ", MYSQL_ERROR(mysql_log), NULL);
628 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,str);
629 615
630 preserve_entry(r, query); 616 /* Attempt a single re-try... First sleep for a tiny amount of time. */
631 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"entry preserved in %s", cls->preserve_file); 617 delay.tv_sec = 0;
632 } else { 618 delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */
633 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"insert successful after a delayed retry."); 619 ret = nanosleep(&delay, &remainder);
634 } 620 if (ret && errno != EINTR)
621 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: nanosleep unsuccessful");
622
623 /* Now make our second attempt */
624 retval = mysql_query(mysql_log,query);
625
626 /* If this one also failed, log that and append to our local offline file */
627 if ( retval != 0 )
628 {
629 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: second attempt failed, API said: %s", MYSQL_ERROR(mysql_log));
630 preserve_entry(r, query);
631 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file);
632 } else {
633 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: second attempt successful");
634 }
635 } 635 }
636 636
637 /* Restore SIGPIPE to its original handler function */ 637 /* Restore SIGPIPE to its original handler function */
@@ -646,43 +646,43 @@ int safe_mysql_query(request_rec *r, const char *query)
646 * to the directives found at Apache runtime. * 646 * to the directives found at Apache runtime. *
647 * ------------------------------------------------*/ 647 * ------------------------------------------------*/
648 648
649const char *set_mysql_massvirtual(cmd_parms *parms, void *dummy, int flag) 649const char *set_log_sql_massvirtual(cmd_parms *parms, void *dummy, int flag)
650{ 650{
651 massvirtual = ( flag ? 1 : 0); 651 massvirtual = ( flag ? 1 : 0);
652 return NULL; 652 return NULL;
653} 653}
654 654
655const char *set_log_mysql_create(cmd_parms *parms, void *dummy, int flag) 655const char *set_log_sql_create(cmd_parms *parms, void *dummy, int flag)
656{ 656{
657 create_tables = ( flag ? 1 : 0); 657 create_tables = ( flag ? 1 : 0);
658 return NULL; 658 return NULL;
659} 659}
660 660
661const char *set_log_mysql_db(cmd_parms *parms, void *dummy, char *arg) 661const char *set_log_sql_db(cmd_parms *parms, void *dummy, char *arg)
662{ 662{
663 db_name = arg; 663 db_name = arg;
664 return NULL; 664 return NULL;
665} 665}
666 666
667const char *set_log_mysql_cookie(cmd_parms *parms, void *dummy, char *arg) 667const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg)
668{ 668{
669 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 669 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
670 670
671 cls->cookie_name = arg; 671 cls->cookie_name = arg;
672 return NULL; 672 return NULL;
673} 673}
674 674
675const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) 675const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg)
676{ 676{
677 /* char *pfile; */ 677 /* char *pfile; */
678 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 678 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
679 679
680 /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */ 680 /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */
681 cls->preserve_file = arg; 681 cls->preserve_file = arg;
682 return NULL; 682 return NULL;
683} 683}
684 684
685const char *set_log_mysql_info(cmd_parms *parms, void *dummy, char *host, char *user, char *pwd) 685const char *set_log_sql_info(cmd_parms *parms, void *dummy, char *host, char *user, char *pwd)
686{ 686{
687 if (*host != '.') { 687 if (*host != '.') {
688 db_host = host; 688 db_host = host;
@@ -696,37 +696,37 @@ const char *set_log_mysql_info(cmd_parms *parms, void *dummy, char *host, char *
696 return NULL; 696 return NULL;
697} 697}
698 698
699const char *set_transfer_log_mysql_table(cmd_parms *parms, void *dummy, char *arg) 699const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg)
700{ 700{
701 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 701 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
702 702
703 if (massvirtual != 0) 703 if (massvirtual != 0)
704 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLTransferLogTable when MySQLMassVirtualHosting is On. Ignoring."); 704 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLTransferLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
705 else 705 else
706 cls->transfer_table_name = arg; 706 cls->transfer_table_name = arg;
707 return NULL; 707 return NULL;
708} 708}
709 709
710const char *set_notes_log_mysql_table(cmd_parms *parms, void *dummy, char *arg) 710const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg)
711{ 711{
712 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 712 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
713 713
714 if (massvirtual != 0) 714 if (massvirtual != 0)
715 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLNotesLogTable when MySQLMassVirtualHosting is On. Ignoring."); 715 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLNotesLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
716 else 716 else
717 cls->notes_table_name = arg; 717 cls->notes_table_name = arg;
718 return NULL; 718 return NULL;
719} 719}
720 720
721const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) 721const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg)
722{ 722{
723 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 723 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
724 724
725 cls->transfer_log_format = arg; 725 cls->transfer_log_format = arg;
726 return NULL; 726 return NULL;
727} 727}
728 728
729const char *set_mysql_socket_file(cmd_parms *parms, void *dummy, char *arg) 729const char *set_log_sql_socket_file(cmd_parms *parms, void *dummy, char *arg)
730{ 730{
731 socket_file = arg; 731 socket_file = arg;
732 732
@@ -734,40 +734,40 @@ const char *set_mysql_socket_file(cmd_parms *parms, void *dummy, char *arg)
734} 734}
735 735
736 736
737const char *add_referer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) 737const char *add_log_sql_referer_ignore(cmd_parms *parms, void *dummy, char *arg)
738{ 738{
739 char **addme; 739 char **addme;
740 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 740 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
741 741
742 addme = push_array(cls->referer_ignore_list); 742 addme = push_array(cls->referer_ignore_list);
743 *addme = pstrdup(cls->referer_ignore_list->pool, arg); 743 *addme = pstrdup(cls->referer_ignore_list->pool, arg);
744 return NULL; 744 return NULL;
745} 745}
746 746
747const char *add_transfer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) 747const char *add_log_sql_transfer_ignore(cmd_parms *parms, void *dummy, char *arg)
748{ 748{
749 char **addme; 749 char **addme;
750 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 750 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
751 751
752 addme = push_array(cls->transfer_ignore_list); 752 addme = push_array(cls->transfer_ignore_list);
753 *addme = pstrdup(cls->transfer_ignore_list->pool, arg); 753 *addme = pstrdup(cls->transfer_ignore_list->pool, arg);
754 return NULL; 754 return NULL;
755} 755}
756 756
757const char *add_remhost_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) 757const char *add_log_sql_remhost_ignore(cmd_parms *parms, void *dummy, char *arg)
758{ 758{
759 char **addme; 759 char **addme;
760 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 760 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
761 761
762 addme = push_array(cls->remhost_ignore_list); 762 addme = push_array(cls->remhost_ignore_list);
763 *addme = pstrdup(cls->remhost_ignore_list->pool, arg); 763 *addme = pstrdup(cls->remhost_ignore_list->pool, arg);
764 return NULL; 764 return NULL;
765} 765}
766 766
767const char *add_mysql_note(cmd_parms *parms, void *dummy, char *arg) 767const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg)
768{ 768{
769 char **addme; 769 char **addme;
770 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 770 log_sql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
771 771
772 addme = push_array(cls->notes_list); 772 addme = push_array(cls->notes_list);
773 *addme = pstrdup(cls->notes_list->pool, arg); 773 *addme = pstrdup(cls->notes_list->pool, arg);
@@ -791,14 +791,14 @@ const char *add_mysql_note(cmd_parms *parms, void *dummy, char *arg)
791 * 791 *
792 * There is no return value. 792 * There is no return value.
793 */ 793 */
794static void log_mysql_child_init(server_rec *s, pool *p) 794static void log_sql_child_init(server_rec *s, pool *p)
795{ 795{
796 int retval; 796 int retval;
797 797
798 retval = open_logdb_link(); 798 retval = open_logdb_link();
799 #ifdef DEBUG 799 #ifdef DEBUG
800 if (retval > 0) { 800 if (retval > 0) {
801 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"open_logdb_link successful"); 801 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"mod_log_sql: open_logdb_link successful");
802 } 802 }
803 #endif 803 #endif
804} 804}
@@ -811,18 +811,18 @@ static void log_mysql_child_init(server_rec *s, pool *p)
811 * 811 *
812 * There is no return value. 812 * There is no return value.
813 */ 813 */
814static void log_mysql_child_exit(server_rec *s, pool *p) 814static void log_sql_child_exit(server_rec *s, pool *p)
815{ 815{
816 mysql_close(mysql_log); 816 mysql_close(mysql_log);
817} 817}
818 818
819 819
820/* 820/*
821void *log_mysql_initializer(server_rec *main_server, pool *p) 821void *log_sql_initializer(server_rec *main_server, pool *p)
822{ 822{
823 server_rec *s; 823 server_rec *s;
824 824
825 log_mysql_state main_conf = ap_get_module_config(main_server->module_config, &mysql_log_module); 825 log_sql_state main_conf = ap_get_module_config(main_server->module_config, &mysql_log_module);
826 826
827 for (server_rec *s = main_server; s; s = s->next) { 827 for (server_rec *s = main_server; s; s = s->next) {
828 conf = ap_get_module_config(s->module_config, &mysql_log_module); 828 conf = ap_get_module_config(s->module_config, &mysql_log_module);
@@ -842,10 +842,10 @@ void *log_mysql_initializer(server_rec *main_server, pool *p)
842 * The return value is a pointer to the created module-specific 842 * The return value is a pointer to the created module-specific
843 * structure. 843 * structure.
844 */ 844 */
845void *log_mysql_make_state(pool *p, server_rec *s) 845void *log_sql_make_state(pool *p, server_rec *s)
846{ 846{
847 847
848 log_mysql_state *cls = (log_mysql_state *) ap_palloc(p, sizeof(log_mysql_state)); 848 log_sql_state *cls = (log_sql_state *) ap_palloc(p, sizeof(log_sql_state));
849 849
850 cls->transfer_table_name = NULL; 850 cls->transfer_table_name = NULL;
851 cls->transfer_log_format = NULL; 851 cls->transfer_log_format = NULL;
@@ -857,7 +857,7 @@ void *log_mysql_make_state(pool *p, server_rec *s)
857 cls->notes_list = make_array(p, 1, sizeof(char *)); 857 cls->notes_list = make_array(p, 1, sizeof(char *));
858 cls->table_made = 0; 858 cls->table_made = 0;
859 859
860 cls->preserve_file = "/tmp/mysql-preserve"; 860 cls->preserve_file = "/tmp/sql-preserve";
861 cls->cookie_name = NULL; 861 cls->cookie_name = NULL;
862 862
863 return (void *) cls; 863 return (void *) cls;
@@ -867,47 +867,47 @@ void *log_mysql_make_state(pool *p, server_rec *s)
867/* Setup of the available httpd.conf configuration commands. 867/* Setup of the available httpd.conf configuration commands.
868 * Structure: command, function called, NULL, where available, how many arguments, verbose description 868 * Structure: command, function called, NULL, where available, how many arguments, verbose description
869 */ 869 */
870command_rec log_mysql_cmds[] = { 870command_rec log_sql_cmds[] = {
871 {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, 871 {"LogSQLTransferLogTable", set_log_sql_transfer_table, NULL, RSRC_CONF, TAKE1,
872 "The MySQL table that holds the transfer log"} 872 "The database table that holds the transfer log"}
873 , 873 ,
874 {"MySQLNotesLogTable", set_notes_log_mysql_table, NULL, RSRC_CONF, TAKE1, 874 {"LogSQLNotesLogTable", set_log_sql_notes_table, NULL, RSRC_CONF, TAKE1,
875 "The MySQL table that holds the notes"} 875 "The database table that holds the notes"}
876 , 876 ,
877 {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1, 877 {"LogSQLTransferLogFormat", set_log_sql_transfer_log_format, NULL, RSRC_CONF, TAKE1,
878 "Instruct the module what information to log to the MySQL transfer log"} 878 "Instruct the module what information to log to the database transfer log"}
879 , 879 ,
880 {"MySQLRefererIgnore", add_referer_mysql_ignore, NULL, RSRC_CONF, ITERATE, 880 {"LogSQLRefererIgnore", add_log_sql_referer_ignore, NULL, RSRC_CONF, ITERATE,
881 "List of referers to ignore. Accesses that match will not be logged to MySQL"} 881 "List of referers to ignore. Accesses that match will not be logged to database"}
882 , 882 ,
883 {"MySQLRequestIgnore", add_transfer_mysql_ignore, NULL, RSRC_CONF, ITERATE, 883 {"LogSQLRequestIgnore", add_log_sql_transfer_ignore, NULL, RSRC_CONF, ITERATE,
884 "List of URIs to ignore. Accesses that match will not be logged to MySQL"} 884 "List of URIs to ignore. Accesses that match will not be logged to database"}
885 , 885 ,
886 {"MySQLRemhostIgnore", add_remhost_mysql_ignore, NULL, RSRC_CONF, ITERATE, 886 {"LogSQLRemhostIgnore", add_log_sql_remhost_ignore, NULL, RSRC_CONF, ITERATE,
887 "List of remote hosts to ignore. Accesses that match will not be logged to MySQL"} 887 "List of remote hosts to ignore. Accesses that match will not be logged to database"}
888 , 888 ,
889 {"MySQLDatabase", set_log_mysql_db, NULL, RSRC_CONF, TAKE1, 889 {"LogSQLDatabase", set_log_sql_db, NULL, RSRC_CONF, TAKE1,
890 "The name of the MySQL database for logging"} 890 "The name of the database database for logging"}
891 , 891 ,
892 {"MySQLWhichCookie", set_log_mysql_cookie, NULL, RSRC_CONF, TAKE1, 892 {"LogSQLWhichCookie", set_log_sql_cookie, NULL, RSRC_CONF, TAKE1,
893 "The CookieName that you want logged when using the 'c' config directive"} 893 "The CookieName that you want logged when using the 'c' config directive"}
894 , 894 ,
895 {"MySQLLoginInfo", set_log_mysql_info, NULL, RSRC_CONF, TAKE3, 895 {"LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF, TAKE3,
896 "The MySQL host, user-id and password for logging"} 896 "The database host, user-id and password for logging"}
897 , 897 ,
898 {"MySQLCreateTables", set_log_mysql_create, NULL, RSRC_CONF, FLAG, 898 {"LogSQLCreateTables", set_log_sql_create, NULL, RSRC_CONF, FLAG,
899 "Turn on module's capability to create its SQL tables on the fly"} 899 "Turn on module's capability to create its SQL tables on the fly"}
900 , 900 ,
901 {"MySQLMassVirtualHosting", set_mysql_massvirtual, NULL, RSRC_CONF, FLAG, 901 {"LogSQLMassVirtualHosting", set_log_sql_massvirtual, NULL, RSRC_CONF, FLAG,
902 "Activates option(s) useful for ISPs performing mass virutal hosting"} 902 "Activates option(s) useful for ISPs performing mass virutal hosting"}
903 , 903 ,
904 {"MySQLPreserveFile", set_log_mysql_preserve_file, NULL, RSRC_CONF, TAKE1, 904 {"LogSQLPreserveFile", set_log_sql_preserve_file, NULL, RSRC_CONF, TAKE1,
905 "Name of the file to use for data preservation during database downtime"} 905 "Name of the file to use for data preservation during database downtime"}
906 , 906 ,
907 {"MySQLSocketFile", set_mysql_socket_file, NULL, RSRC_CONF, TAKE1, 907 {"LogSQLSocketFile", set_log_sql_socket_file, NULL, RSRC_CONF, TAKE1,
908 "Name of the file to employ for socket connections to MySQL"} 908 "Name of the file to employ for socket connections to database"}
909 , 909 ,
910 {"MySQLWhichNotes", add_mysql_note, NULL, RSRC_CONF, ITERATE, 910 {"LogSQLWhichNotes", add_log_sql_note, NULL, RSRC_CONF, ITERATE,
911 "Members of the 'notes' table that you would like to log"} 911 "Members of the 'notes' table that you would like to log"}
912 , 912 ,
913 {NULL} 913 {NULL}
@@ -918,17 +918,17 @@ command_rec log_mysql_cmds[] = {
918/* Routine to perform the actual construction and execution of the relevant 918/* Routine to perform the actual construction and execution of the relevant
919 * INSERT statements. 919 * INSERT statements.
920 */ 920 */
921int log_mysql_transaction(request_rec *orig) 921int log_sql_transaction(request_rec *orig)
922{ 922{
923 char **ptrptr, **ptrptr2; 923 char **ptrptr, **ptrptr2;
924 log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); 924 log_sql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module);
925 const char *access_query; 925 const char *access_query;
926 request_rec *r; 926 request_rec *r;
927 927
928 /* We handle mass virtual hosting differently. Dynamically determine the name 928 /* We handle mass virtual hosting differently. Dynamically determine the name
929 * of the table from the virtual server's name, and flag it for creation. 929 * of the table from the virtual server's name, and flag it for creation.
930 */ 930 */
931 if (massvirtual == 1) { 931 if ( massvirtual == 1 ) {
932 char *access_base = "access_"; 932 char *access_base = "access_";
933 char *notes_base = "notes_"; 933 char *notes_base = "notes_";
934 char *a_tablename; 934 char *a_tablename;
@@ -958,20 +958,21 @@ int log_mysql_transaction(request_rec *orig)
958 } 958 }
959 959
960 /* Do we have enough info to log? */ 960 /* Do we have enough info to log? */
961 if ( ((cls->transfer_table_name == NULL) ? 1 : 0) ) { 961 if ( cls->transfer_table_name == NULL ) {
962 return DECLINED; 962 return DECLINED;
963 } else { 963 } else {
964 const char *thehost; 964 const char *thehost;
965 const char *thenote; 965 const char *thenote;
966 char *fields = "", *values = ""; 966 char *fields = "", *values = "";
967 char *notesets = ""; 967 char *notesets = "";
968 char *note_query = ""; 968 char *note_query = NULL;
969 const char *unique_id; 969 const char *unique_id;
970 const char *formatted_item; 970 const char *formatted_item;
971 int i, j, length; 971 int i, j, length;
972 char *create_access = NULL; 972 char *create_access = NULL;
973 char *create_notes = NULL; 973 char *create_notes = NULL;
974 974 int create_results_access, create_results_notes;
975
975 for (r = orig; r->next; r = r->next) { 976 for (r = orig; r->next; r = r->next) {
976 continue; 977 continue;
977 } 978 }
@@ -1018,17 +1019,17 @@ int log_mysql_transaction(request_rec *orig)
1018 for (i = 0; i < length; i++) { 1019 for (i = 0; i < length; i++) {
1019 j = 0; 1020 j = 0;
1020 1021
1021 while (log_mysql_item_keys[j].ch) { 1022 while (log_sql_item_keys[j].ch) {
1022 1023
1023 if (log_mysql_item_keys[j].ch == cls->transfer_log_format[i]) { 1024 if (log_sql_item_keys[j].ch == cls->transfer_log_format[i]) {
1024 /* Yes, this key is one of the configured keys. 1025 /* Yes, this key is one of the configured keys.
1025 * Call the key's function and put the returned value into 'formatted_item' */ 1026 * Call the key's function and put the returned value into 'formatted_item' */
1026 formatted_item = log_mysql_item_keys[j].func(log_mysql_item_keys[j].want_orig_default ? orig : r, ""); 1027 formatted_item = log_sql_item_keys[j].func(log_sql_item_keys[j].want_orig_default ? orig : r, "");
1027 1028
1028 /* Massage 'formatted_item' for proper SQL eligibility... */ 1029 /* Massage 'formatted_item' for proper SQL eligibility... */
1029 if (!formatted_item) { 1030 if (!formatted_item) {
1030 formatted_item = ""; 1031 formatted_item = "";
1031 } else if (formatted_item[0] == '-' && formatted_item[1] == '\0' && !log_mysql_item_keys[j].string_contents) { 1032 } else if (formatted_item[0] == '-' && formatted_item[1] == '\0' && !log_sql_item_keys[j].string_contents) {
1032 /* If apache tried to log a '-' character for a numeric field, convert that to a zero 1033 /* If apache tried to log a '-' character for a numeric field, convert that to a zero
1033 * because the database expects a numeral and will reject the '-' character. */ 1034 * because the database expects a numeral and will reject the '-' character. */
1034 formatted_item = "0"; 1035 formatted_item = "0";
@@ -1036,12 +1037,12 @@ int log_mysql_transaction(request_rec *orig)
1036 1037
1037 /* Append the fieldname and value-to-insert to the appropriate strings, quoting stringvals with ' as appropriate */ 1038 /* Append the fieldname and value-to-insert to the appropriate strings, quoting stringvals with ' as appropriate */
1038 fields = pstrcat(r->pool, fields, (i > 0 ? "," : ""), 1039 fields = pstrcat(r->pool, fields, (i > 0 ? "," : ""),
1039 log_mysql_item_keys[j].sql_field_name, NULL); 1040 log_sql_item_keys[j].sql_field_name, NULL);
1040 1041
1041 values = pstrcat(r->pool, values, (i > 0 ? "," : ""), 1042 values = pstrcat(r->pool, values, (i > 0 ? "," : ""),
1042 (log_mysql_item_keys[j].string_contents ? "'" : ""), 1043 (log_sql_item_keys[j].string_contents ? "'" : ""),
1043 escape_query(formatted_item, r->pool), 1044 escape_query(formatted_item, r->pool),
1044 (log_mysql_item_keys[j].string_contents ? "'" : ""), NULL); 1045 (log_sql_item_keys[j].string_contents ? "'" : ""), NULL);
1045 break; 1046 break;
1046 } 1047 }
1047 j++; 1048 j++;
@@ -1049,13 +1050,7 @@ int log_mysql_transaction(request_rec *orig)
1049 } 1050 }
1050 } 1051 }
1051 1052
1052 1053 /* Work through the list of notes defined by LogSQLNotesToLog */
1053 /*
1054 fields = pstrcat(r->pool, fields, ",note", NULL);
1055 values = pstrcat(r->pool, values, ",'", NULL);
1056 */
1057
1058 /* Work through the list of notes defined by MySQLNotesToLog */
1059 i = 0; 1054 i = 0;
1060 unique_id = extract_unique_id(r, ""); 1055 unique_id = extract_unique_id(r, "");
1061 1056
@@ -1076,16 +1071,12 @@ int log_mysql_transaction(request_rec *orig)
1076 i++; 1071 i++;
1077 } 1072 }
1078 } 1073 }
1079 note_query = ap_pstrcat(r->pool, note_query, "insert into ", cls->notes_table_name, " (id, item, val) values ", notesets, NULL); 1074 if ( notesets != "" ) {
1080 #ifdef DEBUG 1075 note_query = ap_pstrcat(r->pool, "insert into ", cls->notes_table_name, " (id, item, val) values ", notesets, NULL);
1081 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"note string: %s", note_query); 1076 #ifdef DEBUG
1082 #endif 1077 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query);
1083 1078 #endif
1084 /* 1079 }
1085 values = pstrcat(r->pool, values, "'", NULL);
1086 */
1087
1088
1089 1080
1090 /* Is this virtual server's table flagged as made? We flag it as such in order 1081 /* Is this virtual server's table flagged as made? We flag it as such in order
1091 * to avoid extra processing with each request. If it's not flagged as made, 1082 * to avoid extra processing with each request. If it's not flagged as made,
@@ -1157,21 +1148,32 @@ int log_mysql_transaction(request_rec *orig)
1157 return OK; 1148 return OK;
1158 } else { 1149 } else {
1159 /* Whew, we got the DB link back */ 1150 /* Whew, we got the DB link back */
1160 ap_log_error(APLOG_MARK,NOTICELEVEL,orig->server,"httpd child established database connection"); 1151 ap_log_error(APLOG_MARK,NOTICELEVEL,orig->server,"mod_log_sql: child established database connection");
1161 } 1152 }
1162 } 1153 }
1154
1155
1156 /* So as of here we have a non-null value of mysql_log. */
1157
1163 1158
1164 /* Make the table if we're supposed to */ 1159 /* Make the tables if we're supposed to. */
1165 if ((cls->table_made != 1) && (create_tables != 0)) { 1160 if ((cls->table_made != 1) && (create_tables != 0)) {
1166 mysql_query(mysql_log, create_access); 1161 create_results_access = safe_mysql_query(orig, create_access);
1167 mysql_query(mysql_log, create_notes); 1162 create_results_notes = safe_mysql_query(orig,create_notes);
1168 cls->table_made = 1; 1163
1164 if ( (create_results_access == 0) && (create_results_notes == 0) )
1165 cls->table_made = 1;
1166 else
1167 ap_log_error(APLOG_MARK,ERRLEVEL,orig->server,"mod_log_sql: failed to create all tables, see preserve file");
1169 } 1168 }
1170 1169
1171 /* Make the insert */ 1170 /* Make the access-table insert */
1172 safe_mysql_query(orig, access_query); 1171 safe_mysql_query(orig, access_query);
1173 safe_mysql_query(orig, note_query);
1174 1172
1173 /* If notes are available to log, make the notes-table insert */
1174 if ( note_query != NULL )
1175 safe_mysql_query(orig, note_query);
1176
1175 return OK; 1177 return OK;
1176 } 1178 }
1177} 1179}
@@ -1185,9 +1187,9 @@ module mysql_log_module = {
1185 NULL, /* module initializer */ 1187 NULL, /* module initializer */
1186 NULL, /* create per-dir config */ 1188 NULL, /* create per-dir config */
1187 NULL, /* merge per-dir config */ 1189 NULL, /* merge per-dir config */
1188 log_mysql_make_state, /* create server config */ 1190 log_sql_make_state, /* create server config */
1189 NULL, /* merge server config */ 1191 NULL, /* merge server config */
1190 log_mysql_cmds, /* config directive table */ 1192 log_sql_cmds, /* config directive table */
1191 NULL, /* [9] content handlers */ 1193 NULL, /* [9] content handlers */
1192 NULL, /* [2] URI-to-filename translation */ 1194 NULL, /* [2] URI-to-filename translation */
1193 NULL, /* [5] check/validate user_id */ 1195 NULL, /* [5] check/validate user_id */
@@ -1195,11 +1197,11 @@ module mysql_log_module = {
1195 NULL, /* [4] check access by host */ 1197 NULL, /* [4] check access by host */
1196 NULL, /* [7] MIME type checker/setter */ 1198 NULL, /* [7] MIME type checker/setter */
1197 NULL, /* [8] fixups */ 1199 NULL, /* [8] fixups */
1198 log_mysql_transaction, /* [10] logger */ 1200 log_sql_transaction, /* [10] logger */
1199 NULL /* [3] header parser */ 1201 NULL /* [3] header parser */
1200#if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */ 1202#if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */
1201 ,log_mysql_child_init, /* child process initializer */ 1203 ,log_sql_child_init, /* child process initializer */
1202 log_mysql_child_exit, /* process exit/cleanup */ 1204 log_sql_child_exit, /* process exit/cleanup */
1203 NULL /* [1] post read-request */ 1205 NULL /* [1] post read-request */
1204#endif 1206#endif
1205 1207