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.
17
#include "ap_config.h"
20
#include "http_config.h"
21
#include "http_connection.h"
23
#include "apr_buckets.h"
24
#include "util_filter.h"
26
module AP_MODULE_DECLARE_DATA echo_module;
32
static void *create_echo_server_config(apr_pool_t *p, server_rec *s)
34
EchoConfig *pConfig = apr_pcalloc(p, sizeof *pConfig);
36
pConfig->bEnabled = 0;
41
static const char *echo_on(cmd_parms *cmd, void *dummy, int arg)
43
EchoConfig *pConfig = ap_get_module_config(cmd->server->module_config,
45
pConfig->bEnabled = arg;
50
static int process_echo_connection(conn_rec *c)
52
apr_bucket_brigade *bb;
55
EchoConfig *pConfig = ap_get_module_config(c->base_server->module_config,
58
if (!pConfig->bEnabled) {
63
bb = apr_brigade_create(c->pool, c->bucket_alloc);
65
/* Get a single line of input from the client */
66
if ((rv = ap_get_brigade(c->input_filters, bb, AP_MODE_GETLINE,
67
APR_BLOCK_READ, 0) != APR_SUCCESS ||
68
APR_BRIGADE_EMPTY(bb))) {
69
apr_brigade_destroy(bb);
73
/* Make sure the data is flushed to the client */
74
b = apr_bucket_flush_create(c->bucket_alloc);
75
APR_BRIGADE_INSERT_TAIL(bb, b);
77
/* Send back the data. */
78
rv = ap_pass_brigade(c->output_filters, bb);
79
} while (rv == APR_SUCCESS);
84
static const command_rec echo_cmds[] =
86
AP_INIT_FLAG("ProtocolEcho", echo_on, NULL, RSRC_CONF,
87
"Run an echo server on this host"),
91
static void register_hooks(apr_pool_t *p)
93
ap_hook_process_connection(process_echo_connection, NULL, NULL,
97
module AP_MODULE_DECLARE_DATA echo_module = {
98
STANDARD20_MODULE_STUFF,
99
NULL, /* create per-directory config structure */
100
NULL, /* merge per-directory config structures */
101
create_echo_server_config, /* create per-server config structure */
102
NULL, /* merge per-server config structures */
103
echo_cmds, /* command apr_table_t */
104
register_hooks /* register hooks */