"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* $Id: mod_log_sql_ssl.c 140 2004-05-14 03:50:47Z urkle@drip.ws $ */
2
3 #if defined(WITH_APACHE20)
4 # include "apache20.h"
5 #else
6 # error Unsupported Apache version
7 #endif
8
9 #ifdef HAVE_CONFIG_H
10 /* Undefine these to prevent conflicts between Apache ap_config_auto.h and
11 * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt.
12 */
13 #undef PACKAGE_BUGREPORT
14 #undef PACKAGE_NAME
15 #undef PACKAGE_STRING
16 #undef PACKAGE_TARNAME
17 #undef PACKAGE_VERSION
18
19 #include "config.h"
20 #endif
21
22 #include "mod_log_sql.h"
23
24 module AP_MODULE_DECLARE_DATA log_sql_logio_module;
25
26 // From apachge 2.2's mod_logio.c to provide logging ACTUAL incoming and outgoing bytes
27 static const char logio_filter_name[] = "LOG_SQL_INPUT_OUTPUT";
28
29 typedef struct {
30 apr_off_t bytes_in;
31 apr_off_t bytes_out;
32 } logio_config_t;
33
34 static void ap_logio_add_bytes_out(conn_rec *c, apr_off_t bytes){
35 logio_config_t *cf = ap_get_module_config(c->conn_config, &log_sql_logio_module);
36
37 cf->bytes_out += bytes;
38 }
39
40 static const char *log_bytes_in(request_rec *r, char *a)
41 {
42 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
43 &log_sql_logio_module);
44
45 return apr_off_t_toa(r->pool, cf->bytes_in);
46 }
47
48 static const char *log_bytes_out(request_rec *r, char *a)
49 {
50 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
51 &log_sql_logio_module);
52
53 return apr_off_t_toa(r->pool, cf->bytes_out);
54 }
55
56 static int logio_transaction(request_rec *r)
57 {
58 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
59 &log_sql_logio_module);
60
61 cf->bytes_in = cf->bytes_out = 0;
62
63 return OK;
64 }
65
66 static apr_status_t logio_in_filter(ap_filter_t *f,
67 apr_bucket_brigade *bb,
68 ap_input_mode_t mode,
69 apr_read_type_e block,
70 apr_off_t readbytes) {
71 apr_off_t length;
72 apr_status_t status;
73 logio_config_t *cf = ap_get_module_config(f->c->conn_config, &log_sql_logio_module);
74
75 status = ap_get_brigade(f->next, bb, mode, block, readbytes);
76
77 apr_brigade_length (bb, 0, &length);
78
79 if (length > 0)
80 cf->bytes_in += length;
81
82 return status;
83 }
84
85 static apr_status_t logio_out_filter(ap_filter_t *f,
86 apr_bucket_brigade *bb) {
87 apr_bucket *b = APR_BRIGADE_LAST(bb);
88
89 /* End of data, make sure we flush */
90 if (APR_BUCKET_IS_EOS(b)) {
91 APR_BUCKET_INSERT_BEFORE(b,
92 apr_bucket_flush_create(f->c->bucket_alloc));
93 }
94
95 return ap_pass_brigade(f->next, bb);
96 }
97
98 static int logio_pre_conn(conn_rec *c, void *csd) {
99 logio_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf));
100
101 ap_set_module_config(c->conn_config, &log_sql_logio_module, cf);
102
103 ap_add_input_filter(logio_filter_name, NULL, NULL, c);
104 ap_add_output_filter(logio_filter_name, NULL, NULL, c);
105
106 return OK;
107 }
108
109 static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
110 {
111 log_sql_register_item(s,p,'i', log_bytes_in, "bytes_in", 0, 0);
112 log_sql_register_item(s,p,'o', log_bytes_out, "bytes_out", 0, 0);
113 return OK;
114 }
115 static void register_hooks(apr_pool_t *p) {
116 static const char *pre[] = { "mod_log_sql.c", NULL };
117
118 ap_hook_pre_connection(logio_pre_conn, NULL, NULL, APR_HOOK_MIDDLE);
119 ap_hook_log_transaction(logio_transaction, pre, NULL, APR_HOOK_MIDDLE);
120 ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
121
122 ap_register_input_filter(logio_filter_name, logio_in_filter, NULL,
123 AP_FTYPE_NETWORK - 1);
124 ap_register_output_filter(logio_filter_name, logio_out_filter, NULL,
125 AP_FTYPE_NETWORK - 1);
126
127 APR_REGISTER_OPTIONAL_FN(ap_logio_add_bytes_out);
128 }
129
130 module AP_MODULE_DECLARE_DATA log_sql_logio_module = {
131 STANDARD20_MODULE_STUFF,
132 NULL, NULL, NULL, NULL, NULL, register_hooks
133 };