diff options
-rw-r--r-- | CHANGELOG | 33 | ||||
-rw-r--r-- | mod_log_sql.c | 85 |
2 files changed, 59 insertions, 59 deletions
@@ -1,4 +1,4 @@ | |||
1 | $Id: CHANGELOG,v 1.9 2002/04/21 23:01:52 helios Exp $ | 1 | $Id: CHANGELOG,v 1.10 2002/04/23 03:46:20 helios Exp $ |
2 | 2 | ||
3 | 3 | ||
4 | TODO: | 4 | TODO: |
@@ -7,8 +7,7 @@ TODO: | |||
7 | * Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL. | 7 | * Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL. |
8 | * Fully test create-table | 8 | * Fully test create-table |
9 | * Document new features | 9 | * Document new features |
10 | * preserve and socket configurable in .conf | 10 | * check for mandatory conf directives quit if not |
11 | * segfault when mvh on | ||
12 | 11 | ||
13 | 12 | ||
14 | CHANGES: | 13 | CHANGES: |
@@ -20,7 +19,8 @@ CHANGES: | |||
20 | version the name of the preserve-file was hardcoded and therefore | 19 | version the name of the preserve-file was hardcoded and therefore |
21 | global across all Apache virtual servers. Now the user can configure | 20 | global across all Apache virtual servers. Now the user can configure |
22 | this on a per-virthost basis. It defaults to a hardcoded value | 21 | this on a per-virthost basis. It defaults to a hardcoded value |
23 | if the user does not define it. | 22 | if the user does not define it. The module *always* prepends /tmp/ |
23 | to the user-supplied value for security reasons. | ||
24 | * A new MySQLSocketFile runtime config directive. In the last | 24 | * A new MySQLSocketFile runtime config directive. In the last |
25 | version the name of the MySQL socket was hardcoded. Now the user | 25 | version the name of the MySQL socket was hardcoded. Now the user |
26 | can configure this at Apache runtime. However, it is a global | 26 | can configure this at Apache runtime. However, it is a global |
@@ -28,26 +28,31 @@ CHANGES: | |||
28 | It defaults ot a hardcoded value if the user does not define it. | 28 | It defaults ot a hardcoded value if the user does not define it. |
29 | * A new MySQLCreateTables runtime config directive. Module can now | 29 | * A new MySQLCreateTables runtime config directive. Module can now |
30 | create the access table on-the-fly. Table creation takes place | 30 | create the access table on-the-fly. Table creation takes place |
31 | during the virtual server's first request and is flagged after that. | 31 | during the virtual server's first request and is flagged after that to |
32 | avoid repetition. | ||
32 | * A new MySQLMassVirtualHosting runtime config directive. This flag | 33 | * A new MySQLMassVirtualHosting runtime config directive. This flag |
33 | currently only activates a single feature: each virtual server | 34 | currently only activates a single feature: each virtual server gets |
34 | gets its very own exclusive table prefixed 'access_' with the | 35 | its very own dynamically-determined table prefixed 'access_' with the |
35 | server's name following. It also implies MySQLCreateTables On. | 36 | server's name following. It also implies MySQLCreateTables On, and |
36 | * escape_query (was mysql_escape_log) is now called on every item | 37 | obviates the need for MySQLTransferLogTable. |
38 | * escape_query (was mysql_escape_log) is now called on every item | ||
37 | rather than first checking to see if it needs to be called, which | 39 | rather than first checking to see if it needs to be called, which |
38 | was probably a big waste of time. Furthermore the routine now | 40 | was probably a big waste of time. Furthermore the routine now |
39 | uses a native MySQL API call to do the escaping instead of doing | 41 | uses a native MySQL API call to do the escaping instead of doing |
40 | this 'manually.' It attempts to use the charset-respectful MySQL | 42 | this 'manually.' It attempts to use the charset-respectful MySQL |
41 | call first, but falls back on a more generic call if the MySQL | 43 | call first, but falls back on a more generic call if the MySQL |
42 | server is unavailable (e.g. if it goes offline). | 44 | server is unavailable (e.g. if it goes offline). |
43 | * Open preserve file with pfopen instead of regular fopen to | 45 | * Open preserve file with pfopen instead of regular fopen to |
44 | take advantage of pool structure. | 46 | take advantage of pool structure. |
45 | * As forewarned, I finally got rid of the code to support separate | 47 | * As forewarned, I finally got rid of the code to support separate |
46 | Referer and Agent logs. | 48 | Referer and Agent logs. |
47 | * Finally brought the make process up-to-date with the way Apache | 49 | * Finally brought the make process up-to-date with the way Apache |
48 | likes modules to be done. | 50 | likes modules to be done. |
49 | * Cookies are now configurable on a per-virtualserver basis. Before | 51 | * MySQLWhichCookie is now configurable on a per-virtualserver basis. |
50 | they were on a global basis. | 52 | Before it was single-shot global only. |
53 | * Reduced sleep time on a retry to 1/4 second from 1/2 second. | ||
54 | * Confirmed that this module will compile with -pedantic ... but not | ||
55 | with -ansi. :-) | ||
51 | 56 | ||
52 | 57 | ||
53 | 1.15: | 58 | 1.15: |
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 *); | |||
67 | typedef struct { | 67 | typedef 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 | ||
606 | const char *set_massvirtual(cmd_parms *parms, void *dummy, int flag) | 604 | const 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 | ||
634 | const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) | 632 | const 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 | ||
690 | const char *set_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) | 667 | const 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; |