diff -urN mod_accounting-0.5/Makefile mod_accounting-0.5_modified_clean/Makefile
--- mod_accounting-0.5/Makefile	2001-12-30 17:11:43.000000000 +0300
+++ mod_accounting-0.5_modified_clean/Makefile	2005-07-31 23:43:53.000000000 +0400
@@ -5,7 +5,7 @@
 ##
 
 #   the used tools
-APXS=apxs
+APXS=apxs2
 APACHECTL=apachectl
 
 #   here's what you may need to change
@@ -18,12 +18,13 @@
 
 #   compile the DSO file
 mod_accounting.so: mod_accounting.c postgres.c mysql.c
-	$(APXS) -c $(DEF) $(INC) $(LIB) mod_accounting.c postgres.c mysql.c
+	$(APXS) -Wc,-Wall -Wc,-Werror -Wc,-g -c $(DEF) $(INC) $(LIB) mod_accounting.c postgres.c mysql.c
 
 #   install the DSO file into the Apache installation
 #   and activate it in the Apache configuration
 install: all
-	$(APXS) -i -a -n 'accounting' mod_accounting.so
+	$(APXS) -i mod_accounting.la
+#	$(APXS) -i -a -n 'accounting' mod_accounting.so
 
 #   cleanup
 clean:
diff -urN mod_accounting-0.5/mod_accounting.c mod_accounting-0.5_modified_clean/mod_accounting.c
--- mod_accounting-0.5/mod_accounting.c	2002-09-08 19:17:22.000000000 +0400
+++ mod_accounting-0.5_modified_clean/mod_accounting.c	2005-08-01 09:03:45.000000000 +0400
@@ -26,14 +26,28 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include "apr_strings.h"
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_core.h"
+#include "http_log.h"
+#include "http_request.h"
+#include "http_protocol.h"
+#include "mod_core.h"
 
 #include "mod_accounting.h"
+#include "ctype.h"
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
 
 #define MOD_ACCOUNTING_VERSION_INFO_STRING "mod_accounting/0.5"
 
-module MODULE_VAR_EXPORT accounting_module;
+module AP_MODULE_DECLARE_DATA accounting_module;
 
-typedef int ( *DBQuery )( accounting_state *cfg, server_rec *server, pool *p, char *query );
+typedef int ( *DBQuery )( accounting_state *cfg, server_rec *server, apr_pool_t *p, char *query );
 typedef int ( *DBSetup )( accounting_state *cfg );
 typedef void ( *DBClose )( accounting_state *cfg );
 
@@ -77,12 +91,12 @@
 }
 
 // computes the length of a table
-static long TableLen( request_rec *r, table *tab )
+static long TableLen( request_rec *r, apr_table_t *tab )
 {
 	long count = 0;
 
 	if( tab )
-		ap_table_do((int (*) (void *, const char *, const char *)) GetHeaderLen, (void *) &count, tab, NULL );
+		apr_table_do((int (*) (void *, const char *, const char *)) GetHeaderLen, (void *) &count, tab, NULL );
 
 	return( count );
 }
@@ -100,7 +114,9 @@
 
 	// let's see if it's a failed redirect
 	// I'm using the same logic of ap_send_error_response()
-	if( custom_response = (char *)ap_response_code_string( r, ap_index_of_response( r->status ))) {
+	int status = r->status;
+	int idx = ap_index_of_response( status );
+	if( (custom_response = ap_response_code_string( r, idx))) {
 
 		// if so, find the original request_rec
 		if( custom_response[0] != '"' )
@@ -113,25 +129,32 @@
 	
 	sent = TableLen( r, r->headers_out ) + TableLen( r, r->err_headers_out ) + 2 +	// 2 for CRLF
 		   11 + status_len +														// HTTP/1.x nnn blah
-		   10 + strlen( ap_get_server_version() ) +									// Server: line
-		   8 + strlen( ap_gm_timestr_822( r->pool, r->request_time ));				// Date: line
+		   10 + strlen( ap_get_server_version() ) + 8; // Server: line
+		   // 8 + strlen( ap_gm_timestr_822( r->pool, r->request_time ));				
+		   // // Date: line
 
     if(( sent >= 255 ) && ( sent <= 257 ))
         sent += sizeof( "X-Pad: avoid browser bug" ) + 1;
 
+	ap_log_error( APLOG_MARK, ERRLEVEL, 0, r->server, "MAIN: r->bytes_sent <%u> sent_bodyct <%u> clength <%u>", (int)r->bytes_sent, (int)r->sent_bodyct, (int)r->clength);
 	if( r->sent_bodyct ) {
 
+		ap_log_error( APLOG_MARK, ERRLEVEL, 0, r->server, "r->bytes_sent <%u>", (int)r->bytes_sent);
+		sent += r->bytes_sent;
+#if 0
 		if( r->connection )  {
-			long int bs;
+			ap_log_error( APLOG_MARK, ERRLEVEL, 0, r->server, "r->connection !");
+			// long int bs;
 
 			// this is more accurate than bytes_sent in presence of modules
 			// which manipulate the output (eg. mod_gzip)
-			ap_bgetopt( r->connection->client, BO_BYTECT, &bs );
+			// ap_bgetopt( r->connection->client, BO_BYTECT, &bs );
 		
-			sent += bs;
+			// sent += bs;
 
 		} else
 			sent += r->bytes_sent;
+#endif
 	}
 
 	return( sent );
@@ -150,7 +173,7 @@
 
 	recvd = strlen( r->the_request ) + TableLen( r, r->headers_in ) + 4; // 2 for CRLF after the request, 2 for CRLF after all headers
 
-	len = ap_table_get( r->headers_in, "Content-Length" );
+	len = apr_table_get( r->headers_in, "Content-Length" );
 
 	if( len )
 		recvd += atol( len );
@@ -163,8 +186,8 @@
 {
 	char *user = NULL;
 
-	if( r )
-		user = r->connection->user;
+	// if( r )
+		// user = r->connection->user;
 
 	return( user ? user : "" );
 }
@@ -177,7 +200,7 @@
 	while( ign && !ret ) {
 		unsigned int	ip;
 
-		memcpy( &ip, &r->connection->remote_addr.sin_addr, sizeof( ip ));
+		memcpy( &ip, &r->connection->remote_addr->sa.sin, sizeof( ip ));
 
 		switch( ign->Type ) {
 
@@ -217,8 +240,10 @@
 	int				 i, found = 0;
 	char			 *ptr = arg;
 
-	while( *ptr )
-		*ptr++ = tolower( *ptr );
+	while( *ptr ){
+		*ptr = tolower( *ptr );
+		*ptr++;
+	};
 
 	// let's see if we have the requested driver
 	for( i = 0; i < DB_MAX; i++ )
@@ -283,7 +308,7 @@
 	ignored_host	 host;
 	char			 *ptr, *err = NULL;
 
-	if( ptr = strchr( arg, '-' )) {
+	if( (ptr = strchr( arg, '-' ))) {
 
 		*ptr = '\0';
 
@@ -297,7 +322,7 @@
 		if(( host.IP == INADDR_NONE ) || ( host.Args.IP2 == INADDR_NONE ))
 			err = "Wrong range format";
 
-	} else if( ptr = strchr( arg, '/' )) {
+	} else if( (ptr = strchr( arg, '/' ))) {
 
 		*ptr = '\0';
 
@@ -322,7 +347,7 @@
 	}
 
 	if( !err ) {
-		ignored_host *ign = (ignored_host *)ap_palloc( parms->pool, sizeof( ignored_host ));
+		ignored_host *ign = (ignored_host *)apr_palloc( parms->pool, sizeof( ignored_host ));
 
 		memcpy( ign, &host, sizeof( ignored_host ));
 
@@ -340,6 +365,32 @@
 
 static command_rec acct_cmds[] = 
 {
+	AP_INIT_TAKE1 ("AccountingQueryFmt", (hook_func)set_query_fmt, NULL, RSRC_CONF, 
+	  "The query to execute to log the transactions. "
+	  "Available placeholders are %s for sent bytes, %r for received ones, "
+	  "%h for the virtual host name, %u for the user name." ),
+
+	AP_INIT_TAKE1 ("AccountingDatabase", (hook_func)set_db, NULL, RSRC_CONF, 
+	  "The name of the database for logging" ),
+
+	AP_INIT_TAKE1 ("AccountingDatabaseDriver", (hook_func)set_driver, NULL, RSRC_CONF, 
+	  "The kind of the database for logging" ),
+	
+	AP_INIT_TAKE2 ("AccountingDBHost", (hook_func)set_db_host, NULL, RSRC_CONF, 
+	  "Host and port needed to connect to the database" ),
+
+	AP_INIT_TAKE2 ("AccountingLoginInfo", (hook_func)set_login_info, NULL, RSRC_CONF, 
+	  "User and password required for logging into the database" ),
+
+	AP_INIT_TAKE1 ("AccountingTimedUpdates", (hook_func)set_timed_updates, NULL, RSRC_CONF, 
+	  "Number of seconds to wait between 2 update queries (performance tuning)" ),
+
+	AP_INIT_ITERATE("AccountingIgnoreHosts", (hook_func)add_ignored_hosts, NULL, RSRC_CONF, 
+	  "Ip of hosts to ignore" ),
+	{ NULL }
+};
+
+#if 0
 	{ "AccountingQueryFmt", (hook_func) set_query_fmt, NULL, RSRC_CONF, TAKE1,
 	  "The query to execute to log the transactions. "
 	  "Available placeholders are %s for sent bytes, %r for received ones, "
@@ -366,13 +417,14 @@
 	{ NULL }
 };
 
+#endif 
 
 // ------------------- HOOKS -----------------
 	
 /* Set up space for the various major configuration options */
-static void *acct_make_state( pool *p, server_rec *s )
+static void *acct_make_state( apr_pool_t *p, server_rec *s )
 {
-	accounting_state *cfg = ( accounting_state * ) ap_palloc( p, sizeof( accounting_state ));
+	accounting_state *cfg = ( accounting_state * ) apr_palloc( p, sizeof( accounting_state ));
 
 	memset( cfg, 0, sizeof( *cfg ));
 
@@ -382,7 +434,7 @@
 /* Routine to perform the actual construction and execution of the relevant
  * query
  */
-static void do_query( accounting_state *cfg, pool *p, server_rec *server, request_rec *r )
+static void do_query( accounting_state *cfg, apr_pool_t *p, server_rec *server, request_rec *r )
 {
 	if(!( cfg->Sent || cfg->Received ))
 		return;
@@ -397,7 +449,7 @@
 
 	if(!( *DBDrivers[ cfg->DBDriver ].Setup )( cfg )) {
 
-		ap_log_error( APLOG_MARK, ERRLEVEL, server, "Accounting: couldn't setup the database link!" );
+		ap_log_error( APLOG_MARK, ERRLEVEL, 0, server, "Accounting: couldn't setup the database link!" );
 
 	} else {
 		char *query = "", *ptr = cfg->QueryFmt;
@@ -420,33 +472,33 @@
 				switch( *next++ ) {
 
 					case 'h':
-						query = ap_pstrcat( p, query, ptr, cfg->ServerName ? cfg->ServerName : "-", NULL );
+						query = apr_pstrcat( p, (char*)query, (char*)ptr, cfg->ServerName ? (char*)cfg->ServerName : (char*)"-", NULL );
 						break;
 
 					case 's':
-						query = ap_pstrcat( p, query, ptr, sent, NULL );
+						query = apr_pstrcat( p, (char*)query, (char*)ptr, (char*)sent, NULL );
 						break;
 
 					case 'r':
-						query = ap_pstrcat( p, query, ptr, recvd, NULL );
+						query = apr_pstrcat( p, (char*)query, (char*)ptr, (char*)recvd, NULL );
 						break;
 
 					case 'u':
-						query = ap_pstrcat( p, query, ptr, get_user( r ), NULL );
+						query = apr_pstrcat( p, (char*)query, (char*)ptr, (char*)get_user( r ), NULL );
 						break;
 
 					default:
 						tmp[0] = next[ -1 ];
 						tmp[1] = '\0';
 
-						query = ap_pstrcat( p, query, ptr, tmp, NULL );
+						query = apr_pstrcat( p, query, ptr, tmp, NULL );
 						break;
 				}
 
 				next[ -2 ] = '%';
 
 			} else
-				query = ap_pstrcat( p, query, ptr, NULL );
+				query = apr_pstrcat( p, query, ptr, NULL );
 
 			ptr = next;
 		}
@@ -513,23 +565,48 @@
 }
 
 /* Called on the exit of an httpd child process */
-static void acct_child_exit( server_rec *s, pool *p )
+// static apr_status_t acct_child_exit( server_rec *s, apr_pool_t *p )
+static apr_status_t acct_child_exit( void * data )
 {
+	server_rec * s = (server_rec*)data;
 	accounting_state *cfg = ap_get_module_config( s->module_config, &accounting_module );
 
-	if( cfg->Sent || cfg->Received )
-		do_query( cfg, p, s, NULL );
+	// if( cfg->Sent || cfg->Received )
+		// do_query( cfg, p, s, NULL );
 
 	( *DBDrivers[ cfg->DBDriver ].Close )( cfg );
+	return APR_SUCCESS;
 }
 
-static void mod_acct_init( server_rec *server, pool *p )
+static void mod_acct_init( apr_pool_t *p, server_rec *server )
 {
-	ap_add_version_component(MOD_ACCOUNTING_VERSION_INFO_STRING);
+	ap_add_version_component(p, MOD_ACCOUNTING_VERSION_INFO_STRING);
+
+	apr_pool_cleanup_register (p, server, acct_child_exit, acct_child_exit);
+
 }
 
 // ------------------- MOD CONFIG -----------------
 
+static void
+acct_register_hooks (apr_pool_t * p)
+{
+	ap_hook_child_init (mod_acct_init, NULL, NULL, APR_HOOK_MIDDLE);
+	ap_hook_log_transaction (acct_transaction, NULL, NULL, APR_HOOK_MIDDLE);
+}
+
+module AP_MODULE_DECLARE_DATA accounting_module = {
+	STANDARD20_MODULE_STUFF,
+	NULL,
+	NULL,
+	acct_make_state,
+	NULL,
+	acct_cmds,
+	acct_register_hooks,
+};
+
+
+#if 0
 /* The configuration array that sets up the hooks into the module. */
 module accounting_module = 
 {
@@ -561,3 +638,4 @@
 	NULL					 /* [#0] post read-request */
 #endif  
 };
+#endif
diff -urN mod_accounting-0.5/mod_accounting.h mod_accounting-0.5_modified_clean/mod_accounting.h
--- mod_accounting-0.5/mod_accounting.h	2002-03-05 15:42:08.000000000 +0300
+++ mod_accounting-0.5_modified_clean/mod_accounting.h	2005-07-31 22:07:16.000000000 +0400
@@ -75,13 +75,13 @@
 
 #ifdef NEED_POSTGRES
 extern int PgSetup( accounting_state *cfg );
-extern int PgQuery( accounting_state *cfg, server_rec *server, pool *p, char *query );
+extern int PgQuery( accounting_state *cfg, server_rec *server, apr_pool_t *p, char *query );
 extern void PgClose( accounting_state *cfg );
 #endif
 
 #ifdef NEED_MYSQL
 extern int MySetup( accounting_state *cfg );
-extern int MyQuery( accounting_state *cfg, server_rec *server, pool *p, char *query );
+extern int MyQuery( accounting_state *cfg, server_rec *server, apr_pool_t *p, char *query );
 extern void MyClose( accounting_state *cfg );
 #endif
 
diff -urN mod_accounting-0.5/mysql.c mod_accounting-0.5_modified_clean/mysql.c
--- mod_accounting-0.5/mysql.c	2002-01-05 14:50:50.000000000 +0300
+++ mod_accounting-0.5_modified_clean/mysql.c	2005-07-31 23:02:58.000000000 +0400
@@ -27,6 +27,7 @@
 #include <mysql/mysql.h>
 
 #include "mod_accounting.h"
+#include "apr_strings.h"
 
 #define MYSQL_ERROR( mysql ) (( mysql ) ? ( mysql_error(( MYSQL * )mysql )) : "MySQL server has gone away" )
 
@@ -53,7 +54,7 @@
 	return( cfg->DBHandle != NULL );
 }
 
-int MyQuery( accounting_state *cfg, server_rec *server, pool *p, char *query )
+int MyQuery( accounting_state *cfg, server_rec *server, apr_pool_t *p, char *query )
 {
 	int		retval = 1;
 	void	( *handler )( int );
@@ -66,12 +67,12 @@
 
 		MyClose( cfg );
 
-	    ap_log_error( APLOG_MARK,ERRLEVEL, server, "MySQL: connection lost, attempting reconnect" );
+	    ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "MySQL: connection lost, attempting reconnect" );
 
    		if( MySetup( cfg ))
-	   		ap_log_error( APLOG_MARK,ERRLEVEL, server, "MySQL: reconnect successful" );
+	   		ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "MySQL: reconnect successful" );
 		else
-  			ap_log_error( APLOG_MARK,ERRLEVEL, server, "MySQL: reconnect failed" );
+  			ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "MySQL: reconnect failed" );
 	}
 
 	if( cfg->DBHandle ) {
@@ -80,11 +81,11 @@
 
 		if( retval ) {
 
-			ap_log_error( APLOG_MARK,ERRLEVEL, server, 
-						  ap_pstrcat( p, "MySQL insert failed:  ", query, NULL ));
+			ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, 
+						  apr_pstrcat( p, "MySQL insert failed:  ", query, NULL ));
 
-			ap_log_error( APLOG_MARK, ERRLEVEL, server, 
-						  ap_pstrcat( p, "MySQL failure reason:  ", MYSQL_ERROR( cfg->DBHandle ), NULL ));
+			ap_log_error( APLOG_MARK, ERRLEVEL, 0, server, 
+						  apr_pstrcat( p, "MySQL failure reason:  ", MYSQL_ERROR( cfg->DBHandle ), NULL ));
 		}
 	}
 
diff -urN mod_accounting-0.5/postgres.c mod_accounting-0.5_modified_clean/postgres.c
--- mod_accounting-0.5/postgres.c	2002-01-05 14:50:50.000000000 +0300
+++ mod_accounting-0.5_modified_clean/postgres.c	2005-07-31 23:01:45.000000000 +0400
@@ -27,6 +27,7 @@
 #include <libpq-fe.h>
 
 #include "mod_accounting.h"
+#include "apr_strings.h"
 
 #define PG_ERROR( handle ) (( handle ) ? ( PQerrorMessage(( PGconn * )handle )) : "PostgreSQL server has gone away" )
 
@@ -43,7 +44,7 @@
 	return( cfg->DBHandle != NULL );
 }
 
-int PgQuery( accounting_state *cfg, server_rec *server, pool *p, char *query )
+int PgQuery( accounting_state *cfg, server_rec *server, apr_pool_t *p, char *query )
 {
 	int	retval = 0;
 
@@ -51,12 +52,12 @@
 		
 	    PgClose( cfg );
 
-	    ap_log_error( APLOG_MARK,ERRLEVEL, server, "PostgresSQL: connection lost, attempting reconnect" );
+	    ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "PostgresSQL: connection lost, attempting reconnect" );
 
    		if( !PgSetup( cfg ))
-   			ap_log_error( APLOG_MARK,ERRLEVEL, server, "PostgresSQL: reconnect failed" );
+   			ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "PostgresSQL: reconnect failed" );
 		else
-	   		ap_log_error( APLOG_MARK,ERRLEVEL, server, "PostgresSQL: reconnect successful" );
+	   		ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, "PostgresSQL: reconnect successful" );
 	}
 
 	if( cfg->DBHandle ) {
@@ -68,11 +69,11 @@
 
 		if( !retval ) {
 
-			ap_log_error( APLOG_MARK,ERRLEVEL, server, 
-						  ap_pstrcat( p, "PostgresSQL query failed:  ", query, NULL ));
+			ap_log_error( APLOG_MARK,ERRLEVEL, 0, server, 
+						  apr_pstrcat( p, "PostgresSQL query failed:  ", query, NULL ));
 
-			ap_log_error( APLOG_MARK, ERRLEVEL, server, 
-						  ap_pstrcat( p, "PostgresSQL failure reason:  ", PG_ERROR( cfg->DBHandle ), NULL ));
+			ap_log_error( APLOG_MARK, ERRLEVEL, 0, server, 
+						  apr_pstrcat( p, "PostgresSQL failure reason:  ", PG_ERROR( cfg->DBHandle ), NULL ));
 		}
 
 		PQclear( res );
diff -urN mod_accounting-0.5/schema.sql mod_accounting-0.5_modified_clean/schema.sql
--- mod_accounting-0.5/schema.sql	2002-04-29 23:36:49.000000000 +0400
+++ mod_accounting-0.5_modified_clean/schema.sql	2005-08-01 00:13:56.000000000 +0400
@@ -3,6 +3,14 @@
 	bytesout 	bigint(20),
 	host 		varchar(255)
 );
+
+CREATE TABLE ipacct ( 
+	tstamp	int,
+	vhost	varchar(255),
+	user	varchar(255),
+	bytesin	bigint(20),
+	bytesout	bigint(20)
+);
  
 INSERT INTO ipaccounting VALUES (0, 0, 'www.domainone.com');
 INSERT INTO ipaccounting VALUES (0, 0, 'www.domaintwo.com');
