From 8e6b94ccc7aeddaf63fa8d1b1bcce7d118f28084 Mon Sep 17 00:00:00 2001 From: Christopher Powell Date: Tue, 23 Apr 2002 03:46:20 +0000 Subject: Significant headway toward a releasable 1.16, passed ab testing and my own hand tests. Mods documented in CHANGELOG. --- CHANGELOG | 33 +++++++++++++---------- mod_log_sql.c | 85 ++++++++++++++++++++++++++++------------------------------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a5a4c4f..60318c2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -$Id: CHANGELOG,v 1.9 2002/04/21 23:01:52 helios Exp $ +$Id: CHANGELOG,v 1.10 2002/04/23 03:46:20 helios Exp $ TODO: @@ -7,8 +7,7 @@ TODO: * Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL. * Fully test create-table * Document new features -* preserve and socket configurable in .conf -* segfault when mvh on +* check for mandatory conf directives quit if not CHANGES: @@ -20,7 +19,8 @@ CHANGES: version the name of the preserve-file was hardcoded and therefore global across all Apache virtual servers. Now the user can configure this on a per-virthost basis. It defaults to a hardcoded value - if the user does not define it. + if the user does not define it. The module *always* prepends /tmp/ + to the user-supplied value for security reasons. * A new MySQLSocketFile runtime config directive. In the last version the name of the MySQL socket was hardcoded. Now the user can configure this at Apache runtime. However, it is a global @@ -28,26 +28,31 @@ CHANGES: It defaults ot a hardcoded value if the user does not define it. * A new MySQLCreateTables runtime config directive. Module can now create the access table on-the-fly. Table creation takes place - during the virtual server's first request and is flagged after that. + during the virtual server's first request and is flagged after that to + avoid repetition. * A new MySQLMassVirtualHosting runtime config directive. This flag - currently only activates a single feature: each virtual server - gets its very own exclusive table prefixed 'access_' with the - server's name following. It also implies MySQLCreateTables On. -* escape_query (was mysql_escape_log) is now called on every item + currently only activates a single feature: each virtual server gets + its very own dynamically-determined table prefixed 'access_' with the + server's name following. It also implies MySQLCreateTables On, and + obviates the need for MySQLTransferLogTable. +* escape_query (was mysql_escape_log) is now called on every item rather than first checking to see if it needs to be called, which - was probably a big waste of time. Furthermore the routine now - uses a native MySQL API call to do the escaping instead of doing + was probably a big waste of time. Furthermore the routine now + uses a native MySQL API call to do the escaping instead of doing this 'manually.' It attempts to use the charset-respectful MySQL call first, but falls back on a more generic call if the MySQL server is unavailable (e.g. if it goes offline). -* Open preserve file with pfopen instead of regular fopen to +* Open preserve file with pfopen instead of regular fopen to take advantage of pool structure. * As forewarned, I finally got rid of the code to support separate Referer and Agent logs. * Finally brought the make process up-to-date with the way Apache likes modules to be done. -* Cookies are now configurable on a per-virtualserver basis. Before - they were on a global basis. +* MySQLWhichCookie is now configurable on a per-virtualserver basis. + Before it was single-shot global only. +* Reduced sleep time on a retry to 1/4 second from 1/2 second. +* Confirmed that this module will compile with -pedantic ... but not + with -ansi. :-) 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 @@ -/* $Id: mod_log_sql.c,v 1.9 2002/04/21 23:01:53 helios Exp $ */ +/* $Id: mod_log_sql.c,v 1.10 2002/04/23 03:46:20 helios Exp $ */ /* --------* * DEFINES * @@ -67,8 +67,6 @@ typedef const char *(*item_key_func) (request_rec *, char *); typedef struct { int create_tables; int table_made; - char *referer_table_name; - char *agent_table_name; char *transfer_table_name; array_header *referer_ignore_list; array_header *transfer_ignore_list; @@ -570,7 +568,7 @@ int safe_mysql_query(request_rec *r, const char *query) /* Attempt a single re-try... First sleep for a tiny amount of time. */ delay.tv_sec = 0; - delay.tv_nsec = 500000000; /* max is 999999999 (nine nines) */ + delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */ ret = nanosleep(&delay, &remainder); if (ret && errno != EINTR) ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"nanosleep unsuccessful."); @@ -603,7 +601,7 @@ int safe_mysql_query(request_rec *r, const char *query) * to the directives found at Apache runtime. * * ------------------------------------------------*/ -const char *set_massvirtual(cmd_parms *parms, void *dummy, int flag) +const char *set_mysql_massvirtual(cmd_parms *parms, void *dummy, int flag) { massvirtual = ( flag ? 1 : 0); return NULL; @@ -633,9 +631,11 @@ const char *set_log_mysql_cookie(cmd_parms *parms, void *dummy, char *arg) const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) { + char *pfile; log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); - cls->preserve_file = arg; + pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); + cls->preserve_file = pfile; return NULL; } @@ -657,37 +657,14 @@ const char *set_transfer_log_mysql_table(cmd_parms *parms, void *dummy, char *ar { log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); - if (massvirtual == 1) { - char *base = "access_"; - char *tablename; - int i; - - /* Find memory long enough to hold the table name + \0. */ - /* old way: */ - /* tablename = (char*)ap_palloc(parms->pool, (strlen(base) + strlen(parms->server->server_hostname) + 1) * sizeof(char));*/ - /* strcpy(tablename, base);*/ - /* strcat(tablename, parms->server->server_hostname);*/ - - tablename = ap_pstrcat(parms->pool, base, parms->server->server_hostname, NULL); - - /* Transform any dots to underscores */ - for (i = 0; i < strlen(tablename); i++) { - if (tablename[i] == '.') - tablename[i] = '_'; - } - - /* Tell this virtual server its transfer table name, and - * turn on create_tables, which is implied by massvirtual. - */ - cls->transfer_table_name = tablename; - cls->create_tables = 1; - } else { + if (massvirtual != 0) + ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLTransferLogTable when MySQLMassVirtualHosting is On. Ignoring."); + else cls->transfer_table_name = arg; - } return NULL; } -const char *set_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) +const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) { log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); @@ -829,7 +806,7 @@ command_rec log_mysql_cmds[] = { {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, "The MySQL table that holds the transfer log"} , - {"MySQLTransferLogFormat", set_transfer_log_format, NULL, RSRC_CONF, TAKE1, + {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1, "Instruct the module what information to log to the MySQL transfer log"} , {"MySQLRefererIgnore", add_referer_mysql_ignore, NULL, RSRC_CONF, ITERATE, @@ -853,7 +830,7 @@ command_rec log_mysql_cmds[] = { {"MySQLCreateTables", set_log_mysql_create, NULL, RSRC_CONF, FLAG, "Turn on module's capability to create its SQL tables on the fly"} , - {"MySQLMassVirtualHosting", set_massvirtual, NULL, RSRC_CONF, FLAG, + {"MySQLMassVirtualHosting", set_mysql_massvirtual, NULL, RSRC_CONF, FLAG, "Activates option(s) useful for ISPs performing mass virutal hosting"} , {"MySQLPreserveFile", set_log_mysql_preserve_file, NULL, RSRC_CONF, TAKE1, @@ -876,10 +853,32 @@ int log_mysql_transaction(request_rec *orig) log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); const char *str; request_rec *r; - - /* Are there configuration directives for these SQL logs? For each found - * config directive that is found, mark that type as 'needed'. + + /* We handle mass virtual hosting differently. Dynamically determine the name + * of the table from the virtual server's name, and flag it for creation. */ + if (massvirtual == 1) { + char *base = "access_"; + char *tablename; + int i; + + /* Find memory long enough to hold the table name + \0. */ + tablename = ap_pstrcat(orig->pool, base, ap_get_server_name(orig), NULL); + + /* Transform any dots to underscores */ + for (i = 0; i < strlen(tablename); i++) { + if (tablename[i] == '.') + tablename[i] = '_'; + } + + /* Tell this virtual server its transfer table name, and + * turn on create_tables, which is implied by massvirtual. + */ + cls->transfer_table_name = tablename; + cls->create_tables = 1; + } + + /* Do we have enough info to log? */ if ( ((cls->transfer_table_name == NULL) ? 1 : 0) ) { return DECLINED; } else { @@ -893,6 +892,7 @@ int log_mysql_transaction(request_rec *orig) continue; } + /* The following is a stolen upsetting mess of pointers, I'm sorry * Anyone with the motiviation and/or the time should feel free * 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) virtual_host varchar(50))"; /* Find memory long enough to hold the whole CREATE string + \0 */ - /* old way: - * createstring = (char*)ap_palloc(orig->pool,(strlen(createprefix) + strlen(cls->transfer_table_name) + strlen(createsuffix) + 1) * sizeof(char)); - * strcpy (createstring, createprefix); - * strcat (createstring, cls->transfer_table_name); - * strcat (createstring, createsuffix); */ - createstring = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, createsuffix, NULL); #ifdef DEBUG @@ -1033,7 +1027,8 @@ int log_mysql_transaction(request_rec *orig) ap_log_error(APLOG_MARK,NOTICELEVEL,orig->server,"httpd child established database connection"); } } - + + /* Make the table if we're supposed to */ if ((cls->table_made != 1) && (cls->create_tables != 0)) { mysql_query(mysql_log,createstring); cls->table_made = 1; -- cgit