summaryrefslogtreecommitdiffstats
path: root/mod_log_sql.c
diff options
context:
space:
mode:
authorGravatar Christopher Powell 2002-04-23 03:46:20 +0000
committerGravatar Christopher Powell 2002-04-23 03:46:20 +0000
commit8e6b94ccc7aeddaf63fa8d1b1bcce7d118f28084 (patch)
tree58de042f0cf010258e21fd9620f1301605c9b15a /mod_log_sql.c
parentb63c5d2438aabf0d7721c38387995cb4fb98345f (diff)
Significant headway toward a releasable 1.16, passed ab testing and my
own hand tests. Mods documented in CHANGELOG.
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r--mod_log_sql.c85
1 files changed, 40 insertions, 45 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 02b0dd7..fc46853 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,4 +1,4 @@
1/* $Id: mod_log_sql.c,v 1.9 2002/04/21 23:01:53 helios Exp $ */ 1/* $Id: mod_log_sql.c,v 1.10 2002/04/23 03:46:20 helios Exp $ */
2 2
3/* --------* 3/* --------*
4 * DEFINES * 4 * DEFINES *
@@ -67,8 +67,6 @@ typedef const char *(*item_key_func) (request_rec *, char *);
67typedef struct { 67typedef struct {
68 int create_tables; 68 int create_tables;
69 int table_made; 69 int table_made;
70 char *referer_table_name;
71 char *agent_table_name;
72 char *transfer_table_name; 70 char *transfer_table_name;
73 array_header *referer_ignore_list; 71 array_header *referer_ignore_list;
74 array_header *transfer_ignore_list; 72 array_header *transfer_ignore_list;
@@ -570,7 +568,7 @@ int safe_mysql_query(request_rec *r, const char *query)
570 568
571 /* Attempt a single re-try... First sleep for a tiny amount of time. */ 569 /* Attempt a single re-try... First sleep for a tiny amount of time. */
572 delay.tv_sec = 0; 570 delay.tv_sec = 0;
573 delay.tv_nsec = 500000000; /* max is 999999999 (nine nines) */ 571 delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */
574 ret = nanosleep(&delay, &remainder); 572 ret = nanosleep(&delay, &remainder);
575 if (ret && errno != EINTR) 573 if (ret && errno != EINTR)
576 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"nanosleep unsuccessful."); 574 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"nanosleep unsuccessful.");
@@ -603,7 +601,7 @@ int safe_mysql_query(request_rec *r, const char *query)
603 * to the directives found at Apache runtime. * 601 * to the directives found at Apache runtime. *
604 * ------------------------------------------------*/ 602 * ------------------------------------------------*/
605 603
606const char *set_massvirtual(cmd_parms *parms, void *dummy, int flag) 604const char *set_mysql_massvirtual(cmd_parms *parms, void *dummy, int flag)
607{ 605{
608 massvirtual = ( flag ? 1 : 0); 606 massvirtual = ( flag ? 1 : 0);
609 return NULL; 607 return NULL;
@@ -633,9 +631,11 @@ const char *set_log_mysql_cookie(cmd_parms *parms, void *dummy, char *arg)
633 631
634const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) 632const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg)
635{ 633{
634 char *pfile;
636 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 635 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
637 636
638 cls->preserve_file = arg; 637 pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL);
638 cls->preserve_file = pfile;
639 return NULL; 639 return NULL;
640} 640}
641 641
@@ -657,37 +657,14 @@ const char *set_transfer_log_mysql_table(cmd_parms *parms, void *dummy, char *ar
657{ 657{
658 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 658 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
659 659
660 if (massvirtual == 1) { 660 if (massvirtual != 0)
661 char *base = "access_"; 661 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLTransferLogTable when MySQLMassVirtualHosting is On. Ignoring.");
662 char *tablename; 662 else
663 int i;
664
665 /* Find memory long enough to hold the table name + \0. */
666 /* old way: */
667 /* tablename = (char*)ap_palloc(parms->pool, (strlen(base) + strlen(parms->server->server_hostname) + 1) * sizeof(char));*/
668 /* strcpy(tablename, base);*/
669 /* strcat(tablename, parms->server->server_hostname);*/
670
671 tablename = ap_pstrcat(parms->pool, base, parms->server->server_hostname, NULL);
672
673 /* Transform any dots to underscores */
674 for (i = 0; i < strlen(tablename); i++) {
675 if (tablename[i] == '.')
676 tablename[i] = '_';
677 }
678
679 /* Tell this virtual server its transfer table name, and
680 * turn on create_tables, which is implied by massvirtual.
681 */
682 cls->transfer_table_name = tablename;
683 cls->create_tables = 1;
684 } else {
685 cls->transfer_table_name = arg; 663 cls->transfer_table_name = arg;
686 }
687 return NULL; 664 return NULL;
688} 665}
689 666
690const char *set_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) 667const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg)
691{ 668{
692 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 669 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
693 670
@@ -829,7 +806,7 @@ command_rec log_mysql_cmds[] = {
829 {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, 806 {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1,
830 "The MySQL table that holds the transfer log"} 807 "The MySQL table that holds the transfer log"}
831 , 808 ,
832 {"MySQLTransferLogFormat", set_transfer_log_format, NULL, RSRC_CONF, TAKE1, 809 {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1,
833 "Instruct the module what information to log to the MySQL transfer log"} 810 "Instruct the module what information to log to the MySQL transfer log"}
834 , 811 ,
835 {"MySQLRefererIgnore", add_referer_mysql_ignore, NULL, RSRC_CONF, ITERATE, 812 {"MySQLRefererIgnore", add_referer_mysql_ignore, NULL, RSRC_CONF, ITERATE,
@@ -853,7 +830,7 @@ command_rec log_mysql_cmds[] = {
853 {"MySQLCreateTables", set_log_mysql_create, NULL, RSRC_CONF, FLAG, 830 {"MySQLCreateTables", set_log_mysql_create, NULL, RSRC_CONF, FLAG,
854 "Turn on module's capability to create its SQL tables on the fly"} 831 "Turn on module's capability to create its SQL tables on the fly"}
855 , 832 ,
856 {"MySQLMassVirtualHosting", set_massvirtual, NULL, RSRC_CONF, FLAG, 833 {"MySQLMassVirtualHosting", set_mysql_massvirtual, NULL, RSRC_CONF, FLAG,
857 "Activates option(s) useful for ISPs performing mass virutal hosting"} 834 "Activates option(s) useful for ISPs performing mass virutal hosting"}
858 , 835 ,
859 {"MySQLPreserveFile", set_log_mysql_preserve_file, NULL, RSRC_CONF, TAKE1, 836 {"MySQLPreserveFile", set_log_mysql_preserve_file, NULL, RSRC_CONF, TAKE1,
@@ -876,10 +853,32 @@ int log_mysql_transaction(request_rec *orig)
876 log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); 853 log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module);
877 const char *str; 854 const char *str;
878 request_rec *r; 855 request_rec *r;
879 856
880 /* Are there configuration directives for these SQL logs? For each found 857 /* We handle mass virtual hosting differently. Dynamically determine the name
881 * config directive that is found, mark that type as 'needed'. 858 * of the table from the virtual server's name, and flag it for creation.
882 */ 859 */
860 if (massvirtual == 1) {
861 char *base = "access_";
862 char *tablename;
863 int i;
864
865 /* Find memory long enough to hold the table name + \0. */
866 tablename = ap_pstrcat(orig->pool, base, ap_get_server_name(orig), NULL);
867
868 /* Transform any dots to underscores */
869 for (i = 0; i < strlen(tablename); i++) {
870 if (tablename[i] == '.')
871 tablename[i] = '_';
872 }
873
874 /* Tell this virtual server its transfer table name, and
875 * turn on create_tables, which is implied by massvirtual.
876 */
877 cls->transfer_table_name = tablename;
878 cls->create_tables = 1;
879 }
880
881 /* Do we have enough info to log? */
883 if ( ((cls->transfer_table_name == NULL) ? 1 : 0) ) { 882 if ( ((cls->transfer_table_name == NULL) ? 1 : 0) ) {
884 return DECLINED; 883 return DECLINED;
885 } else { 884 } else {
@@ -893,6 +892,7 @@ int log_mysql_transaction(request_rec *orig)
893 continue; 892 continue;
894 } 893 }
895 894
895
896 /* The following is a stolen upsetting mess of pointers, I'm sorry 896 /* The following is a stolen upsetting mess of pointers, I'm sorry
897 * Anyone with the motiviation and/or the time should feel free 897 * Anyone with the motiviation and/or the time should feel free
898 * to make this cleaner, and while at it, clean the same mess at the RefererLog part :) */ 898 * to make this cleaner, and while at it, clean the same mess at the RefererLog part :) */
@@ -994,12 +994,6 @@ int log_mysql_transaction(request_rec *orig)
994 virtual_host varchar(50))"; 994 virtual_host varchar(50))";
995 995
996 /* Find memory long enough to hold the whole CREATE string + \0 */ 996 /* Find memory long enough to hold the whole CREATE string + \0 */
997 /* old way:
998 * createstring = (char*)ap_palloc(orig->pool,(strlen(createprefix) + strlen(cls->transfer_table_name) + strlen(createsuffix) + 1) * sizeof(char));
999 * strcpy (createstring, createprefix);
1000 * strcat (createstring, cls->transfer_table_name);
1001 * strcat (createstring, createsuffix); */
1002
1003 createstring = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, createsuffix, NULL); 997 createstring = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, createsuffix, NULL);
1004 998
1005 #ifdef DEBUG 999 #ifdef DEBUG
@@ -1033,7 +1027,8 @@ int log_mysql_transaction(request_rec *orig)
1033 ap_log_error(APLOG_MARK,NOTICELEVEL,orig->server,"httpd child established database connection"); 1027 ap_log_error(APLOG_MARK,NOTICELEVEL,orig->server,"httpd child established database connection");
1034 } 1028 }
1035 } 1029 }
1036 1030
1031 /* Make the table if we're supposed to */
1037 if ((cls->table_made != 1) && (cls->create_tables != 0)) { 1032 if ((cls->table_made != 1) && (cls->create_tables != 0)) {
1038 mysql_query(mysql_log,createstring); 1033 mysql_query(mysql_log,createstring);
1039 cls->table_made = 1; 1034 cls->table_made = 1;