1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
* Originally written @ Covalent by Jim Jagielski
23
* Think of this as a filter sniffer for Apache 2.x. It logs
24
* all filter data right before and after it goes out on the
25
* wire (BUT right before SSL encoded or after SSL decoded).
26
* It can produce a *huge* amount of data.
31
#include "http_connection.h"
32
#include "http_config.h"
33
#include "http_core.h"
36
module AP_MODULE_DECLARE_DATA dumpio_module ;
38
typedef struct dumpio_conf_t {
44
* Workhorse function: simply log to the current error_log
45
* info about the data in the bucket as well as the data itself
47
static void dumpit(ap_filter_t *f, apr_bucket *b)
51
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,
52
"mod_dumpio: %s (%s-%s): %" APR_SIZE_T_FMT " bytes",
54
(APR_BUCKET_IS_METADATA(b)) ? "metadata" : "data",
58
if (!(APR_BUCKET_IS_METADATA(b))) {
62
if (apr_bucket_read(b, &buf, &nbytes, APR_BLOCK_READ) == APR_SUCCESS) {
64
obuf = malloc(nbytes+1); /* use pool? */
65
memcpy(obuf, buf, nbytes);
67
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,
68
"mod_dumpio: %s (%s-%s): %s",
70
(APR_BUCKET_IS_METADATA(b)) ? "metadata" : "data",
76
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,
77
"mod_dumpio: %s (%s-%s): %s",
79
(APR_BUCKET_IS_METADATA(b)) ? "metadata" : "data",
81
"error reading data");
86
#define whichmode( mode ) \
87
( (( mode ) == AP_MODE_READBYTES) ? "readbytes" : \
88
(( mode ) == AP_MODE_GETLINE) ? "getline" : \
89
(( mode ) == AP_MODE_EATCRLF) ? "eatcrlf" : \
90
(( mode ) == AP_MODE_SPECULATIVE) ? "speculative" : \
91
(( mode ) == AP_MODE_EXHAUSTIVE) ? "exhaustive" : \
92
(( mode ) == AP_MODE_INIT) ? "init" : "unknown" \
95
static int dumpio_input_filter (ap_filter_t *f, apr_bucket_brigade *bb,
96
ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
103
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,
104
"mod_dumpio: %s [%s-%s] %" APR_OFF_T_FMT " readbytes",
107
((block) == APR_BLOCK_READ) ? "blocking" : "nonblocking",
110
ret = ap_get_brigade(f->next, bb, mode, block, readbytes);
112
if (ret == APR_SUCCESS) {
113
for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) {
117
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server,
118
"mod_dumpio: %s - %d", f->frec->name, ret) ;
124
static int dumpio_output_filter (ap_filter_t *f, apr_bucket_brigade *bb)
129
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, c->base_server, "mod_dumpio: %s", f->frec->name) ;
131
for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) {
133
* If we ever see an EOS, make sure to FLUSH.
135
if (APR_BUCKET_IS_EOS(b)) {
136
apr_bucket *flush = apr_bucket_flush_create(f->c->bucket_alloc);
137
APR_BUCKET_INSERT_BEFORE(b, flush);
142
return ap_pass_brigade(f->next, bb) ;
145
static int dumpio_pre_conn(conn_rec *c, void *csd)
148
(dumpio_conf_t *) ap_get_module_config(c->base_server->module_config,
151
if (ptr->enable_input)
152
ap_add_input_filter("DUMPIO_IN", NULL, NULL, c);
153
if (ptr->enable_output)
154
ap_add_output_filter("DUMPIO_OUT", NULL, NULL, c);
158
static void dumpio_register_hooks(apr_pool_t *p)
161
* We know that SSL is CONNECTION + 5
163
ap_register_output_filter("DUMPIO_OUT", dumpio_output_filter,
164
NULL, AP_FTYPE_CONNECTION + 3) ;
166
ap_register_input_filter("DUMPIO_IN", dumpio_input_filter,
167
NULL, AP_FTYPE_CONNECTION + 3) ;
169
ap_hook_pre_connection(dumpio_pre_conn, NULL, NULL, APR_HOOK_MIDDLE);
172
static void *dumpio_create_sconfig(apr_pool_t *p, server_rec *s)
174
dumpio_conf_t *ptr = apr_pcalloc(p, sizeof *ptr);
175
ptr->enable_input = ptr->enable_output = 0;
179
static const char *dumpio_enable_input(cmd_parms *cmd, void *dummy, int arg)
182
(dumpio_conf_t *) ap_get_module_config(cmd->server->module_config,
185
ptr->enable_input = arg;
189
static const char *dumpio_enable_output(cmd_parms *cmd, void *dummy, int arg)
192
(dumpio_conf_t *) ap_get_module_config(cmd->server->module_config,
195
ptr->enable_output = arg;
199
static const command_rec dumpio_cmds[] = {
200
AP_INIT_FLAG("DumpIOInput", dumpio_enable_input, NULL,
201
RSRC_CONF, "Enable I/O Dump on Input Data"),
202
AP_INIT_FLAG("DumpIOOutput", dumpio_enable_output, NULL,
203
RSRC_CONF, "Enable I/O Dump on Output Data"),
207
module AP_MODULE_DECLARE_DATA dumpio_module = {
208
STANDARD20_MODULE_STUFF,
211
dumpio_create_sconfig,
214
dumpio_register_hooks