diff options
author | Edward Rudd | 2004-01-20 20:33:20 +0000 |
---|---|---|
committer | Edward Rudd | 2004-01-20 20:33:20 +0000 |
commit | a5d838fab50df5d39396470b2bc9bf25e81cad53 (patch) | |
tree | 01968c890dc1c74ec00dd650646a3adf65b4c3e8 /mod_log_sql.c | |
parent | ccd1b379bfc208c34ad61fc42cac4a797af6d153 (diff) |
Added item registration function and added functions to new system header mod_log_sql.h
Registered core item functions in pre_config
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r-- | mod_log_sql.c | 88 |
1 files changed, 51 insertions, 37 deletions
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 @@ | |||
1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.8 2004/01/20 19:38:08 urkle Exp $ */ | 1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.9 2004/01/20 20:33:20 urkle Exp $ */ |
2 | /* --------* | 2 | /* --------* |
3 | * DEFINES * | 3 | * DEFINES * |
4 | * --------*/ | 4 | * --------*/ |
@@ -43,6 +43,7 @@ | |||
43 | #include <limits.h> | 43 | #include <limits.h> |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #include "mod_log_sql.h" | ||
46 | 47 | ||
47 | /* Configuratino Defaults */ | 48 | /* Configuratino Defaults */ |
48 | #define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" | 49 | #define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" |
@@ -83,8 +84,6 @@ typedef struct { | |||
83 | 84 | ||
84 | static global_config_t global_config; | 85 | static global_config_t global_config; |
85 | 86 | ||
86 | typedef const char *(*item_key_func) (request_rec *, char *); | ||
87 | |||
88 | /* But the contents of this structure will vary by virtual server. | 87 | /* But the contents of this structure will vary by virtual server. |
89 | * This permits each virtual server to vary its configuration slightly | 88 | * This permits each virtual server to vary its configuration slightly |
90 | * for per-server customization. | 89 | * for per-server customization. |
@@ -116,6 +115,30 @@ typedef struct { | |||
116 | 115 | ||
117 | static int safe_create_tables(logsql_state *cls, request_rec *r); | 116 | static int safe_create_tables(logsql_state *cls, request_rec *r); |
118 | 117 | ||
118 | typedef struct { | ||
119 | log_sql_item_func *func; /* its extraction function */ | ||
120 | const char *sql_field_name; /* its column in SQL */ | ||
121 | int want_orig_default; /* if it requires the original request prior to internal redirection */ | ||
122 | int string_contents; /* if it returns a string */ | ||
123 | } log_sql_item; | ||
124 | |||
125 | apr_hash_t *log_sql_hash; | ||
126 | |||
127 | /* Registration Function for extract functions */ | ||
128 | LOGSQL_DECLARE(void) log_sql_register_item(apr_pool_t *p, char *key, | ||
129 | log_sql_item_func *func, const char *sql_field_name, | ||
130 | int want_orig_default, int string_contents) | ||
131 | { | ||
132 | log_sql_item *item = apr_palloc(p, sizeof(log_sql_item)); | ||
133 | /*item->key = */ | ||
134 | item->func = func; | ||
135 | item->sql_field_name = sql_field_name; | ||
136 | item->want_orig_default = want_orig_default; | ||
137 | item->string_contents = string_contents; | ||
138 | /* TODO: find apache 13 way of doing this */ | ||
139 | apr_hash_set(log_sql_hash, key, APR_HASH_KEY_STRING, item); | ||
140 | } | ||
141 | |||
119 | /* Include all the extract functions */ | 142 | /* Include all the extract functions */ |
120 | #include "functions.h" | 143 | #include "functions.h" |
121 | #if defined(WITH_APACHE13) | 144 | #if defined(WITH_APACHE13) |
@@ -124,40 +147,6 @@ static int safe_create_tables(logsql_state *cls, request_rec *r); | |||
124 | # include "functions20.h" | 147 | # include "functions20.h" |
125 | #endif | 148 | #endif |
126 | 149 | ||
127 | struct log_sql_item_list { | ||
128 | char ch; /* its letter code */ | ||
129 | item_key_func func; /* its extraction function */ | ||
130 | const char *sql_field_name; /* its column in SQL */ | ||
131 | int want_orig_default; /* if it requires the original request prior to internal redirection */ | ||
132 | int string_contents; /* if it returns a string */ | ||
133 | } static log_sql_item_keys[] = { | ||
134 | |||
135 | { 'A', extract_agent, "agent", 1, 1 }, | ||
136 | { 'a', extract_request_args, "request_args", 1, 1 }, | ||
137 | { 'b', extract_bytes_sent, "bytes_sent", 0, 0 }, | ||
138 | { 'c', extract_cookie, "cookie", 0, 1 }, | ||
139 | { 'e', extract_env_var, "env_var", 0, 1 }, | ||
140 | { 'f', extract_request_file, "request_file", 0, 1 }, | ||
141 | { 'H', extract_request_protocol, "request_protocol", 0, 1 }, | ||
142 | { 'h', extract_remote_host, "remote_host", 0, 1 }, | ||
143 | { 'I', extract_unique_id, "id", 0, 1 }, | ||
144 | { 'l', extract_remote_logname, "remote_logname", 0, 1 }, | ||
145 | { 'm', extract_request_method, "request_method", 0, 1 }, | ||
146 | { 'M', extract_machine_id, "machine_id", 0, 1 }, | ||
147 | { 'P', extract_child_pid, "child_pid", 0, 0 }, | ||
148 | { 'p', extract_server_port, "server_port", 0, 0 }, | ||
149 | { 'R', extract_referer, "referer", 1, 1 }, | ||
150 | { 'r', extract_request_line, "request_line", 1, 1 }, | ||
151 | { 'S', extract_request_timestamp, "time_stamp", 0, 0 }, | ||
152 | { 's', extract_status, "status", 1, 0 }, | ||
153 | { 'T', extract_request_duration, "request_duration", 1, 0 }, | ||
154 | { 't', extract_request_time, "request_time", 0, 1 }, | ||
155 | { 'u', extract_remote_user, "remote_user", 0, 1 }, | ||
156 | { 'U', extract_request_uri, "request_uri", 1, 1 }, | ||
157 | { 'v', extract_virtual_host, "virtual_host", 0, 1 }, | ||
158 | {'\0'} | ||
159 | }; | ||
160 | |||
161 | /* Routine to escape the 'dangerous' characters that would otherwise | 150 | /* Routine to escape the 'dangerous' characters that would otherwise |
162 | * corrupt the INSERT string: ', \, and " | 151 | * corrupt the INSERT string: ', \, and " |
163 | */ | 152 | */ |
@@ -700,6 +689,31 @@ static void log_sql_pre_config(server_rec *s, apr_pool_t *p) | |||
700 | if (!global_config.tcpport) | 689 | if (!global_config.tcpport) |
701 | global_config.tcpport = 3306; | 690 | global_config.tcpport = 3306; |
702 | 691 | ||
692 | /* Register handlers */ | ||
693 | log_sql_register_item(p,"A", extract_agent, "agent", 1, 1); | ||
694 | log_sql_register_item(p,"a", extract_request_args, "request_args", 1, 1); | ||
695 | log_sql_register_item(p,"b", extract_bytes_sent, "bytes_sent", 0, 0); | ||
696 | log_sql_register_item(p,"c", extract_cookie, "cookie", 0, 1); | ||
697 | log_sql_register_item(p,"e", extract_env_var, "env_var", 0, 1); | ||
698 | log_sql_register_item(p,"f", extract_request_file, "request_file", 0, 1); | ||
699 | log_sql_register_item(p,"H", extract_request_protocol, "request_protocol", 0, 1); | ||
700 | log_sql_register_item(p,"h", extract_remote_host, "remote_host", 0, 1); | ||
701 | log_sql_register_item(p,"I", extract_unique_id, "id", 0, 1); | ||
702 | log_sql_register_item(p,"l", extract_remote_logname, "remote_logname", 0, 1); | ||
703 | log_sql_register_item(p,"m", extract_request_method, "request_method", 0, 1); | ||
704 | log_sql_register_item(p,"M", extract_machine_id, "machine_id", 0, 1); | ||
705 | log_sql_register_item(p,"P", extract_child_pid, "child_pid", 0, 0); | ||
706 | log_sql_register_item(p,"p", extract_server_port, "server_port", 0, 0); | ||
707 | log_sql_register_item(p,"R", extract_referer, "referer", 1, 1); | ||
708 | log_sql_register_item(p,"r", extract_request_line, "request_line", 1, 1); | ||
709 | log_sql_register_item(p,"S", extract_request_timestamp, "time_stamp", 0, 0); | ||
710 | log_sql_register_item(p,"s", extract_status, "status", 1, 0); | ||
711 | log_sql_register_item(p,"T", extract_request_duration, "request_duration", 1, 0); | ||
712 | log_sql_register_item(p,"t", extract_request_time, "request_time", 0, 1); | ||
713 | log_sql_register_item(p,"u", extract_remote_user, "remote_user", 0, 1); | ||
714 | log_sql_register_item(p,"U", extract_request_uri, "request_uri", 1, 1); | ||
715 | log_sql_register_item(p,"v", extract_virtual_host, "virtual_host", 0, 1); | ||
716 | |||
703 | #if defined(WITH_APACHE20) | 717 | #if defined(WITH_APACHE20) |
704 | return OK; | 718 | return OK; |
705 | #endif | 719 | #endif |