mod_echo.c revision 7619b51fca6ecf16c28389e52a666e82f3c8d3ef
6ae232055d4d8a97267517c5e50074c2c819941and/* Licensed to the Apache Software Foundation (ASF) under one or more
6ae232055d4d8a97267517c5e50074c2c819941and * contributor license agreements. See the NOTICE file distributed with
6ae232055d4d8a97267517c5e50074c2c819941and * this work for additional information regarding copyright ownership.
6ae232055d4d8a97267517c5e50074c2c819941and * The ASF licenses this file to You under the Apache License, Version 2.0
6ae232055d4d8a97267517c5e50074c2c819941and * (the "License"); you may not use this file except in compliance with
6ae232055d4d8a97267517c5e50074c2c819941and * the License. You may obtain a copy of the License at
6ae232055d4d8a97267517c5e50074c2c819941and * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
b43f840409794ed298e8634f6284741f193b6c4ftakashitypedef struct {
6ae232055d4d8a97267517c5e50074c2c819941andstatic void *create_echo_server_config(apr_pool_t *p, server_rec *s)
6ae232055d4d8a97267517c5e50074c2c819941andstatic const char *echo_on(cmd_parms *cmd, void *dummy, int arg)
6ae232055d4d8a97267517c5e50074c2c819941and EchoConfig *pConfig = ap_get_module_config(cmd->server->module_config,
6ae232055d4d8a97267517c5e50074c2c819941andstatic apr_status_t brigade_peek(apr_bucket_brigade *bbIn,
1d980e5489836e977ba59b419e27b0ec875c4bd3takashi /* compensate for NULL */
6ae232055d4d8a97267517c5e50074c2c819941and while ((b != APR_BRIGADE_SENTINEL(bbIn)) && (readbytes < bufflen)) {
6ae232055d4d8a97267517c5e50074c2c819941and const char *pos;
6ae232055d4d8a97267517c5e50074c2c819941and const char *str;
6ae232055d4d8a97267517c5e50074c2c819941and if ((rv = apr_bucket_read(b, &str, &len, APR_NONBLOCK_READ))
6ae232055d4d8a97267517c5e50074c2c819941and /* initial pass only, please - in the name of efficiency */
6ae232055d4d8a97267517c5e50074c2c819941and /* Deliberate trailing space - filling in string on WRITE passes */
6ae232055d4d8a97267517c5e50074c2c819941and /* each subsequent WRITE pass, let's update what we echoed */
6ae232055d4d8a97267517c5e50074c2c819941and brigade_peek(last_echoed, ws->request + sizeof("ECHO ") - 1,
6ae232055d4d8a97267517c5e50074c2c819941and EchoConfig *pConfig = ap_get_module_config(c->base_server->module_config,
6ae232055d4d8a97267517c5e50074c2c819941and update_echo_child_status(c->sbh, SERVER_BUSY_READ, c, NULL);
6ae232055d4d8a97267517c5e50074c2c819941and for ( ; ; ) {
6ae232055d4d8a97267517c5e50074c2c819941and /* Get a single line of input from the client */
6ae232055d4d8a97267517c5e50074c2c819941and if (((rv = ap_get_brigade(c->input_filters, bb, AP_MODE_GETLINE,
6ae232055d4d8a97267517c5e50074c2c819941and if (!APR_STATUS_IS_EOF(rv) && ! APR_STATUS_IS_TIMEUP(rv))
6ae232055d4d8a97267517c5e50074c2c819941and ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01611)
6ae232055d4d8a97267517c5e50074c2c819941and "ProtocolEcho: Failure reading from %s",
6ae232055d4d8a97267517c5e50074c2c819941and /* Something horribly wrong happened. Someone didn't block! */
6ae232055d4d8a97267517c5e50074c2c819941and ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01612)
6ae232055d4d8a97267517c5e50074c2c819941and "ProtocolEcho: Error - read empty brigade from %s!",
6ae232055d4d8a97267517c5e50074c2c819941and apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout);
6ae232055d4d8a97267517c5e50074c2c819941and update_echo_child_status(c->sbh, SERVER_BUSY_WRITE, NULL, bb);
6ae232055d4d8a97267517c5e50074c2c819941and /* Make sure the data is flushed to the client */
6ae232055d4d8a97267517c5e50074c2c819941and ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01613)
6ae232055d4d8a97267517c5e50074c2c819941and "ProtocolEcho: Failure writing to %s",
6ae232055d4d8a97267517c5e50074c2c819941and /* Announce our intent to loop */
6ae232055d4d8a97267517c5e50074c2c819941and update_echo_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, NULL, NULL);
6ae232055d4d8a97267517c5e50074c2c819941and update_echo_child_status(c->sbh, SERVER_CLOSING, c, NULL);
6ae232055d4d8a97267517c5e50074c2c819941and "Run an echo server on this host"),
6ae232055d4d8a97267517c5e50074c2c819941and ap_hook_process_connection(process_echo_connection, NULL, NULL,
6ae232055d4d8a97267517c5e50074c2c819941and create_echo_server_config, /* create per-server config structure */