From 7c378cc1fac4e9fec1ca32d8d314ea86761a7404 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Thu, 29 Apr 2004 21:19:30 +0000 Subject: win32 updates and build script added LogSQLDisablePreserve set default of preserve file to root_relative logs/mod_log_sql-preserve --- diff --git a/CHANGELOG b/CHANGELOG index f0540f8..4beccec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,12 @@ +1.98: 2004-04-? +* re-fixed apache.m4 to better detect APR and APU code +* fixed for win32 compilation under apache 2 +* lowered minumum required apache 2 version to 2.0.40 (RH9) +* Added LogSQLDisablePreserve to disable the preserve file. +* Changed default preserve file location to logs/mod_log_sql-preserve + And made LogSQLPreserveFile root relative. +* fixed bug where preserve file wouldn't be created in apache 2 + 1.97: 2004-04-08 * fixed apache.m4 to work with apache 2 setups with different include directories for APR and APU then core Apache diff --git a/build-apache2.bat b/build-apache2.bat new file mode 100644 index 0000000..f44109c --- /dev/null +++ b/build-apache2.bat @@ -0,0 +1,40 @@ +@echo off +rem path to Microsoft SDK installation +SET DIR_MSSDK=C:\Program Files\Microsoft SDK +rem path to apache2 installation +SET DIR_APACHE=C:\Program Files\Apache Group\Apache2 +rem path to mysql 4.0 installation +SET DIR_MYSQL=C:\MySQL +rem Can be set to opt or debug +SET LIB_MYSQL=opt + +copy /Y winconfig.h config.h +mkdir Release +cd Release +Rem Compile all the source code +echo /MD /W3 /Zi /O2 /DNDEBUG /D_WINDOWS /DWIN32 > RESP_c.txt +echo /Fd"mod_log_sql" /FD >> RESP_c.txt +echo /DHAVE_CONFIG_H /DWITH_APACHE20 /DLOGSQL_DECLARE_EXPORT >> RESP_c.txt +echo /I.. >> RESP_c.txt +echo /I"%DIR_MSSDK%\Include" >> RESP_c.txt +echo /I"%DIR_APACHE%\Include" >> RESP_c.txt +echo /I"%DIR_MYSQL%\Include" >> RESP_c.txt +cl @RESP_c.txt /c ..\mod_log_sql.c ..\mod_log_sql_mysql.c + +rem link main module +echo /MACHINE:I386 /SUBSYSTEM:windows > RESP_l.txt +echo /OUT:mod_log_sql.so /DLL /OPT:REF /DEBUG >> RESP_l.txt +echo /LIBPATH:"%DIR_APACHE%\lib" >> RESP_l.txt +echo libapr.lib libaprutil.lib libhttpd.lib >> RESP_l.txt +link @RESP_l.txt mod_log_sql.obj + +rem link mysql module +echo /MACHINE:I386 /SUBSYSTEM:windows > RESP_l.txt +echo /OUT:mod_log_sql_mysql.so /DLL /OPT:REF /DEBUG >> RESP_l.txt +echo /LIBPATH:"%DIR_APACHE%\lib" >> RESP_l.txt +echo /LIBPATH:"%DIR_MYSQL%\lib\%LIB_MYSQL%" >> RESP_l.txt +echo /NODEFAULTLIB:LIBCMT.lib >> RESP_l.txt +echo libapr.lib libaprutil.lib libhttpd.lib >> RESP_l.txt +echo libmysql.lib mod_log_sql.lib >> RESP_l.txt +link @RESP_l.txt mod_log_sql_mysql.obj +cd .. diff --git a/mod_log_sql.c b/mod_log_sql.c index 83a303a..0ba1bf6 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -36,7 +36,7 @@ #define DEFAULT_HIN_TABLE_NAME "headers_in" #define DEFAULT_HOUT_TABLE_NAME "headers_out" #define DEFAULT_COOKIE_TABLE_NAME "cookies" -#define DEFAULT_PRESERVE_FILE "/tmp/sql-preserve" +#define DEFAULT_PRESERVE_FILE "logs/mod_log_sql-preserve" /* -------------* * DECLARATIONS * @@ -54,6 +54,7 @@ typedef struct { int massvirtual; int createtables; int forcepreserve; + int disablepreserve; char *machid; int announce; logsql_dbconnection db; @@ -193,14 +194,20 @@ static void preserve_entry(request_rec *r, const char *query) #if defined(WITH_APACHE20) apr_file_t *fp; apr_status_t result; - result = apr_file_open(&fp, cls->preserve_file,APR_APPEND, APR_OS_DEFAULT, r->pool); #elif defined(WITH_APACHE13) FILE *fp; int result; + #endif + /* If preserve file is disabled bail out */ + if (global_config.disablepreserve) + return; + #if defined(WITH_APACHE20) + result = apr_file_open(&fp, cls->preserve_file,APR_APPEND | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, r->pool); + #elif defined(WITH_APACHE13) fp = ap_pfopen(r->pool, cls->preserve_file, "a"); result = (fp)?0:errno; - #endif - if (result != APR_SUCCESS) { + #endif + if (result != APR_SUCCESS) { log_error(APLOG_MARK, APLOG_ERR, result, r->server, "attempted append of local preserve file '%s' but failed.",cls->preserve_file); } else { @@ -272,6 +279,27 @@ static const char *set_server_string_slot(cmd_parms *cmd, return NULL; } +static const char *set_server_file_slot(cmd_parms *cmd, + void *struct_ptr, + const char *arg) +{ + void *ptr = ap_get_module_config(cmd->server->module_config, + &log_sql_module); + int offset = (int)(long)cmd->info; + const char *path; + + path = ap_server_root_relative(cmd->pool, arg); + + if (!path) { + return apr_pstrcat(cmd->pool, "Invalid file path ", + arg, NULL); + } + + *(const char **)((char*)ptr + offset) = path; + + return NULL; +} + static const char *set_logformat_slot(cmd_parms *cmd, void *struct_ptr, const char *arg) @@ -325,6 +353,7 @@ static const char *set_log_sql_info(cmd_parms *cmd, void *dummy, const char *host, const char *user, const char *pwd) { if (!user) { /* user is null, so only one arg passed */ + /* TODO: to more error checking/force all params to be set */ apr_uri_t uri; apr_uri_parse(cmd->pool, host, &uri); if (uri.scheme) { @@ -372,7 +401,7 @@ static const char *add_server_string_slot(cmd_parms *cmd, void *ptr = ap_get_module_config(cmd->server->module_config, &log_sql_module); int offset = (int)(long)cmd->info; - apr_array_header_t *ary = *(apr_array_header_t **)(ptr + offset); + apr_array_header_t *ary = *(apr_array_header_t **)((char *)ptr + offset); addme = apr_array_push(ary); *addme = apr_pstrdup(ary->pool, arg); @@ -464,7 +493,17 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p) if (global_config.announce) { ap_add_version_component(p, PACKAGE_NAME"/"PACKAGE_VERSION); } - + /* ap_server_root_relative any default preserve file locations */ + { + server_rec *cur_s; + const char *default_p = ap_server_root_relative(p, DEFAULT_PRESERVE_FILE); + for (cur_s = s; cur_s != NULL; cur_s= cur_s->next) { + logsql_state *cls = ap_get_module_config(cur_s->module_config, + &log_sql_module); + if (cls->preserve_file == DEFAULT_PRESERVE_FILE) + cls->preserve_file = default_p; + } + } #if defined(WITH_APACHE20) return OK; #endif @@ -693,7 +732,10 @@ static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv) if (child->preserve_file == DEFAULT_PRESERVE_FILE) child->preserve_file = parent->preserve_file; - + /* server_root_relative the preserve file location */ + if (child->preserve_file == DEFAULT_PRESERVE_FILE) + child->preserve_file = ap_server_root_relative(p, DEFAULT_PRESERVE_FILE); + if (child->notes_table_name == DEFAULT_NOTES_TABLE_NAME) child->notes_table_name = parent->notes_table_name; @@ -1070,7 +1112,7 @@ static const command_rec log_sql_cmds[] = { , /* DB connection parameters */ AP_INIT_TAKE13("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF, - "The database connection URI in the form
driver://user:password@hostname:port/database") + "The database connection URI in the form "driver://user:password@hostname:port/database"") , AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF, "First argument is the DB parameter, second is the value to assign") @@ -1079,7 +1121,11 @@ static const command_rec log_sql_cmds[] = { (void *)APR_OFFSETOF(global_config_t, forcepreserve), RSRC_CONF, "Forces logging to preserve file and bypasses database") , - AP_INIT_TAKE1("LogSQLPreserveFile", set_server_string_slot, + AP_INIT_FLAG("LogSQLDisablePreserve", set_global_flag_slot, + (void *)APR_OFFSETOF(global_config_t, disablepreserve), RSRC_CONF, + "Completely disables use of the preserve file") + , + AP_INIT_TAKE1("LogSQLPreserveFile", set_server_file_slot, (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF, "Name of the file to use for data preservation during database downtime") , diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c index 3749d64..e8a149e 100644 --- a/mod_log_sql_mysql.c +++ b/mod_log_sql_mysql.c @@ -109,13 +109,22 @@ static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p, return from_str; } } - +#if defined(WIN32) +#define SIGNAL_GRAB +#define SIGNAL_RELEASE +#define SIGNAL_VAR +#else +#define SIGNAL_VAR void (*handler) (int) +#define SIGNAL_GRAB handler = signal(SIGPIPE, SIG_IGN) +#define SIGNAL_RELEASE signal(SIGPIPE, handler); +#endif /* Run a mysql insert query and return a categorized error or success */ static logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db, const char *query) { int retval; - void (*handler) (int); + SIGNAL_VAR + unsigned int real_error = 0; /*const char *real_error_str = NULL;*/ @@ -124,12 +133,13 @@ static logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection * if (!dblink) { return LOGSQL_QUERY_NOLINK; } + /* A failed mysql_query() may send a SIGPIPE, so we ignore that signal momentarily. */ - handler = signal(SIGPIPE, SIG_IGN); + SIGNAL_GRAB /* Run the query */ if (!(retval = mysql_query(dblink, query))) { - signal(SIGPIPE, handler); + SIGNAL_RELEASE return LOGSQL_QUERY_SUCCESS; } /* Check to see if the error is "nonexistent table" */ @@ -138,12 +148,12 @@ static logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection * if (real_error == ER_NO_SUCH_TABLE) { log_error(APLOG_MARK,APLOG_ERR,0, r->server,"table does not exist, preserving query"); /* Restore SIGPIPE to its original handler function */ - signal(SIGPIPE, handler); + SIGNAL_RELEASE return LOGSQL_QUERY_NOTABLE; } /* Restore SIGPIPE to its original handler function */ - signal(SIGPIPE, handler); + SIGNAL_RELEASE return LOGSQL_QUERY_FAIL; } @@ -153,7 +163,7 @@ static logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection { int retval; const char *tabletype = apr_table_get(db->parms,"tabletype"); - void (*handler) (int); + SIGNAL_VAR char *type_suffix = NULL; char *create_prefix = "create table if not exists `"; @@ -220,16 +230,16 @@ static logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection return LOGSQL_QUERY_NOLINK; } /* A failed mysql_query() may send a SIGPIPE, so we ignore that signal momentarily. */ - handler = signal(SIGPIPE, SIG_IGN); + SIGNAL_GRAB /* Run the create query */ if ((retval = mysql_query(dblink, create_sql))) { log_error(APLOG_MARK,APLOG_ERR,0, r->server,"failed to create table: %s", table_name); - signal(SIGPIPE, handler); + SIGNAL_RELEASE return LOGSQL_TABLE_FAIL; } - signal(SIGPIPE, handler); + SIGNAL_RELEASE return LOGSQL_TABLE_SUCCESS; } diff --git a/winconfig.h b/winconfig.h index 89d1b24..107cb7d 100644 --- a/winconfig.h +++ b/winconfig.h @@ -2,16 +2,16 @@ /* config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 +/* #undef HAVE_INTTYPES_H */ /* Define to 1 if you have the `m' library (-lm). */ -#define HAVE_LIBM 1 +/* #undef HAVE_LIBM */ /* Define to 1 if you have the `mysqlclient' library (-lmysqlclient). */ #define HAVE_LIBMYSQLCLIENT 1 /* Define to 1 if you have the `z' library (-lz). */ -#define HAVE_LIBZ 1 +/* #undef HAVE_LIBZ */ /* Define to 1 if you have the header file. */ #define HAVE_LIMITS_H 1 @@ -20,31 +20,31 @@ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the header file. */ -#define HAVE_MOD_SSL_H 1 +/* #undef HAVE_MOD_SSL_H */ /* Define to 1 if you have the `mysql_real_escape_string' function. */ #define HAVE_MYSQL_REAL_ESCAPE_STRING 1 /* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 +/* #undef HAVE_STDINT_H */ /* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 +/* #undef HAVE_STDLIB_H 1 /* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 +/* #undef HAVE_STRINGS_H */ /* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 +/* #undef HAVE_STRING_H */ /* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 +/* #undef HAVE_SYS_STAT_H */ /* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 +/* #undef HAVE_SYS_TYPES_H */ /* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 +/* #undef HAVE_UNISTD_H */ /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "" @@ -65,7 +65,7 @@ /* #undef STDC_HEADERS */ /* Define if we want to compile in SSL support. */ -#define WANT_SSL_LOGGING +/* #undef WANT_SSL_LOGGING */ /* Define to 1 if we are compiling with Apache 1.3.x */ /* #undef WITH_APACHE13 */ @@ -75,3 +75,4 @@ /* Define to 1 if we are compiling with mysql */ #define WITH_MYSQL 1 + -- cgit v0.9.2