From a5d838fab50df5d39396470b2bc9bf25e81cad53 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 20 Jan 2004 20:33:20 +0000 Subject: Added item registration function and added functions to new system header mod_log_sql.h Registered core item functions in pre_config --- diff --git a/Makefile.in b/Makefile.in index 27ba01f..5b1d1ec 100644 --- a/Makefile.in +++ b/Makefile.in @@ -5,7 +5,11 @@ SUBDIRS = Documentation SOURCES = \ @PACKAGE_NAME@.c -HEADERS = +HEADERS = functions.h \ + functions13.h \ + functions20.h \ + apache13.h \ + apache20.h CFLAGS = -Wc,-Wall -Wc,-Werror -Wc,-fno-strict-aliasing @@ -15,7 +19,7 @@ LDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ EXTRA_DIST = INSTALL LICENSE CHANGELOG make_combined_log.pl -TARGET = @APACHE_OUTPUT_NAME@ +TARGET = @PACKAGE_NAME@@APXS_EXTENSION@ #Don't modify anything below here @@ -59,7 +63,7 @@ all-subdirs install-subdirs activate-subdirs clean-subdirs distclean-subdirs: fi; \ done; -$(TARGET): +$(TARGET): $(SOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(TARGET) $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) \ $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES) @@ -74,7 +78,7 @@ activate: activate-subdirs @@APXS_BIN@ -i -a $(TARGET) clean: clean-subdirs - $(RM) $(OBJ) $(SLO) $(LO) $(TARGET) .deps + $(RM) $(OBJ) $(SLO) $(LO) $(TARGET) $(RM) -r .libs distclean: clean distclean-subdirs @@ -110,16 +114,6 @@ local-dist: $(DISTFILES) @mkdir -p $(DESTDIR); \ cp -dp --parents $(DISTFILES) $(DESTDIR); -$(builddir)/.deps: depend - -depend: $(SOURCES) $(HEADERS) - if test -n "`ls $(srcdir)/*.c 2> /dev/null`"; then \ - $(CC) -MM -I@APACHE_INCDIR@ @MOD_SSL_CFLAGS@ $(INCLUDES) @DEFS@ \ - @APACHE_DEFS@ $(srcdir)/*.c > $(builddir)/.deps || true; \ - fi - -include $(builddir)/.deps - .PHONY: include all-subdirs activate-subdirs install-subdirs \ clean-subdirs distclean-subdirs dist diff --git a/m4/apache.m4 b/m4/apache.m4 index 93319e3..a72343c 100644 --- a/m4/apache.m4 +++ b/m4/apache.m4 @@ -139,7 +139,7 @@ AC_ARG_ENABLE( AC_MSG_RESULT(yes) AC_DEFINE(WITH_APACHE20,1,[Define to 1 if we are compiling with Apache 2.0.x]) APACHE_VERSION="20" - APACHE_OUTPUT_NAME=$PACKAGE_NAME.la + APXS_EXTENSION=.la APACHE_DEFS="-DWITH_APACHE20" ifelse([$4], , , $4), AC_MSG_RESULT(no) @@ -154,7 +154,7 @@ AC_ARG_ENABLE( AC_MSG_RESULT(yes) AC_DEFINE(WITH_APACHE13,1,[Define to 1 if we are compiling with Apache 1.3.x]) APACHE_VERSION="13" - APACHE_OUTPUT_NAME=$PACKAGE_NAME.so + APXS_EXTENSION=.so APACHE_DEFS="-DWITH_APACHE13" ifelse([$3], , , $3), AC_MSG_RESULT(no) @@ -167,6 +167,6 @@ AC_ARG_ENABLE( AC_SUBST(APACHE_INCDIR) AC_SUBST(APACHE_MODDIR) AC_SUBST(APACHE_VERSION) - AC_SUBST(APACHE_OUTPUT_NAME) + AC_SUBST(APXS_EXTENSION) fi ]) diff --git a/mod_log_sql.c b/mod_log_sql.c index 1ce4a44..95c8c62 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -1,4 +1,4 @@ -/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.8 2004/01/20 19:38:08 urkle Exp $ */ +/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.9 2004/01/20 20:33:20 urkle Exp $ */ /* --------* * DEFINES * * --------*/ @@ -43,6 +43,7 @@ #include #endif +#include "mod_log_sql.h" /* Configuratino Defaults */ #define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" @@ -83,8 +84,6 @@ typedef struct { static global_config_t global_config; -typedef const char *(*item_key_func) (request_rec *, char *); - /* But the contents of this structure will vary by virtual server. * This permits each virtual server to vary its configuration slightly * for per-server customization. @@ -116,6 +115,30 @@ typedef struct { static int safe_create_tables(logsql_state *cls, request_rec *r); +typedef struct { + log_sql_item_func *func; /* its extraction function */ + const char *sql_field_name; /* its column in SQL */ + int want_orig_default; /* if it requires the original request prior to internal redirection */ + int string_contents; /* if it returns a string */ +} log_sql_item; + +apr_hash_t *log_sql_hash; + +/* Registration Function for extract functions */ +LOGSQL_DECLARE(void) log_sql_register_item(apr_pool_t *p, char *key, + log_sql_item_func *func, const char *sql_field_name, + int want_orig_default, int string_contents) +{ + log_sql_item *item = apr_palloc(p, sizeof(log_sql_item)); + /*item->key = */ + item->func = func; + item->sql_field_name = sql_field_name; + item->want_orig_default = want_orig_default; + item->string_contents = string_contents; + /* TODO: find apache 13 way of doing this */ + apr_hash_set(log_sql_hash, key, APR_HASH_KEY_STRING, item); +} + /* Include all the extract functions */ #include "functions.h" #if defined(WITH_APACHE13) @@ -124,40 +147,6 @@ static int safe_create_tables(logsql_state *cls, request_rec *r); # include "functions20.h" #endif -struct log_sql_item_list { - char ch; /* its letter code */ - item_key_func func; /* its extraction function */ - const char *sql_field_name; /* its column in SQL */ - int want_orig_default; /* if it requires the original request prior to internal redirection */ - int string_contents; /* if it returns a string */ - } static log_sql_item_keys[] = { - - { 'A', extract_agent, "agent", 1, 1 }, - { 'a', extract_request_args, "request_args", 1, 1 }, - { 'b', extract_bytes_sent, "bytes_sent", 0, 0 }, - { 'c', extract_cookie, "cookie", 0, 1 }, - { 'e', extract_env_var, "env_var", 0, 1 }, - { 'f', extract_request_file, "request_file", 0, 1 }, - { 'H', extract_request_protocol, "request_protocol", 0, 1 }, - { 'h', extract_remote_host, "remote_host", 0, 1 }, - { 'I', extract_unique_id, "id", 0, 1 }, - { 'l', extract_remote_logname, "remote_logname", 0, 1 }, - { 'm', extract_request_method, "request_method", 0, 1 }, - { 'M', extract_machine_id, "machine_id", 0, 1 }, - { 'P', extract_child_pid, "child_pid", 0, 0 }, - { 'p', extract_server_port, "server_port", 0, 0 }, - { 'R', extract_referer, "referer", 1, 1 }, - { 'r', extract_request_line, "request_line", 1, 1 }, - { 'S', extract_request_timestamp, "time_stamp", 0, 0 }, - { 's', extract_status, "status", 1, 0 }, - { 'T', extract_request_duration, "request_duration", 1, 0 }, - { 't', extract_request_time, "request_time", 0, 1 }, - { 'u', extract_remote_user, "remote_user", 0, 1 }, - { 'U', extract_request_uri, "request_uri", 1, 1 }, - { 'v', extract_virtual_host, "virtual_host", 0, 1 }, - {'\0'} -}; - /* Routine to escape the 'dangerous' characters that would otherwise * corrupt the INSERT string: ', \, and " */ @@ -700,6 +689,31 @@ static void log_sql_pre_config(server_rec *s, apr_pool_t *p) if (!global_config.tcpport) global_config.tcpport = 3306; + /* Register handlers */ + log_sql_register_item(p,"A", extract_agent, "agent", 1, 1); + log_sql_register_item(p,"a", extract_request_args, "request_args", 1, 1); + log_sql_register_item(p,"b", extract_bytes_sent, "bytes_sent", 0, 0); + log_sql_register_item(p,"c", extract_cookie, "cookie", 0, 1); + log_sql_register_item(p,"e", extract_env_var, "env_var", 0, 1); + log_sql_register_item(p,"f", extract_request_file, "request_file", 0, 1); + log_sql_register_item(p,"H", extract_request_protocol, "request_protocol", 0, 1); + log_sql_register_item(p,"h", extract_remote_host, "remote_host", 0, 1); + log_sql_register_item(p,"I", extract_unique_id, "id", 0, 1); + log_sql_register_item(p,"l", extract_remote_logname, "remote_logname", 0, 1); + log_sql_register_item(p,"m", extract_request_method, "request_method", 0, 1); + log_sql_register_item(p,"M", extract_machine_id, "machine_id", 0, 1); + log_sql_register_item(p,"P", extract_child_pid, "child_pid", 0, 0); + log_sql_register_item(p,"p", extract_server_port, "server_port", 0, 0); + log_sql_register_item(p,"R", extract_referer, "referer", 1, 1); + log_sql_register_item(p,"r", extract_request_line, "request_line", 1, 1); + log_sql_register_item(p,"S", extract_request_timestamp, "time_stamp", 0, 0); + log_sql_register_item(p,"s", extract_status, "status", 1, 0); + log_sql_register_item(p,"T", extract_request_duration, "request_duration", 1, 0); + log_sql_register_item(p,"t", extract_request_time, "request_time", 0, 1); + log_sql_register_item(p,"u", extract_remote_user, "remote_user", 0, 1); + log_sql_register_item(p,"U", extract_request_uri, "request_uri", 1, 1); + log_sql_register_item(p,"v", extract_virtual_host, "virtual_host", 0, 1); + #if defined(WITH_APACHE20) return OK; #endif diff --git a/mod_log_sql.h b/mod_log_sql.h new file mode 100644 index 0000000..90f4c06 --- /dev/null +++ b/mod_log_sql.h @@ -0,0 +1,33 @@ +/* $Header: /home/cvs/mod_log_sql/mod_log_sql.h,v 1.1 2004/01/20 20:33:20 urkle Exp $ */ +#ifndef MOD_LOG_SQL_H +#define MOD_LOG_SQL_H + +/* Create a set of LOGSQL_DECLARE(type), LOGSQL_DECLARE_NONSTD(type) and + * LOGSQL_DECLARE_DATA with appropriate export and import tags for the platform + */ +#if !defined(WIN32) +#define LOGSQL_DECLARE(type) type +#define LOGSQL_DECLARE_NONSTD(type) type +#define LOGSQL_DECLARE_DATA +#elif defined(LOGSQL_DECLARE_STATIC) +#define LOGSQL_DECLARE(type) type __stdcall +#define LOGSQL_DECLARE_NONSTD(type) type +#define LOGSQL_DECLARE_DATA +#elif defined(LOGSQL_DECLARE_EXPORT) +#define LOGSQL_DECLARE(type) __declspec(dllexport) type __stdcall +#define LOGSQL_DECLARE_NONSTD(type) __declspec(dllexport) type +#define LOGSQL_DECLARE_DATA __declspec(dllexport) +#else +#define LOGSQL_DECLARE(type) __declspec(dllimport) type __stdcall +#define LOGSQL_DECLARE_NONSTD(type) __declspec(dllimport) type +#define LOGSQL_DECLARE_DATA __declspec(dllimport) +#endif + +typedef const char *log_sql_item_func(request_rec *r, char *a); + +/* Registration Function for extract functions */ +LOGSQL_DECLARE(void) log_sql_register_item(apr_pool_t *p, char *key, + log_sql_item_func *func, const char *sql_field_name, + int want_orig_default, int string_contents); + +#endif /* MOD_LOG_SQL_H */ diff --git a/mod_log_sql.prj b/mod_log_sql.prj index 7fa3b1b..571d182 100644 --- a/mod_log_sql.prj +++ b/mod_log_sql.prj @@ -53,7 +53,13 @@ anjuta.program.arguments= module.include.name=. module.include.type= module.include.expanded=0 -module.include.files= +module.include.files=\ + apache13.h\ + apache20.h\ + functions.h\ + functions13.h\ + functions20.h\ + mod_log_sql.h module.source.name=. module.source.type= diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c index 3346d2f..c1901a0 100644 --- a/mod_log_sql_ssl.c +++ b/mod_log_sql_ssl.c @@ -1,4 +1,4 @@ -/* $Header: /home/cvs/mod_log_sql/mod_log_sql_ssl.c,v 1.1 2004/01/20 19:38:08 urkle Exp $ */ +/* $Header: /home/cvs/mod_log_sql/mod_log_sql_ssl.c,v 1.2 2004/01/20 20:33:20 urkle Exp $ */ /* mod_log_sql_ssl */ #if defined(WITH_APACHE20) @@ -93,8 +93,8 @@ static const char *extract_ssl_cipher(request_rec *r, char *a) } } -#ifdef WANT_SSL_LOGGING + + { 'q', extract_ssl_keysize, "ssl_keysize", 0, 1 }, { 'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1 }, { 'z', extract_ssl_cipher, "ssl_cipher", 0, 1 }, -#endif -- cgit v0.9.2