af84459fbf938e508fd10b01cb8d699c79083813takashi/* Licensed to the Apache Software Foundation (ASF) under one or more
af84459fbf938e508fd10b01cb8d699c79083813takashi * contributor license agreements. See the NOTICE file distributed with
af84459fbf938e508fd10b01cb8d699c79083813takashi * this work for additional information regarding copyright ownership.
af84459fbf938e508fd10b01cb8d699c79083813takashi * The ASF licenses this file to You under the Apache License, Version 2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi * (the "License"); you may not use this file except in compliance with
af84459fbf938e508fd10b01cb8d699c79083813takashi * the License. You may obtain a copy of the License at
af84459fbf938e508fd10b01cb8d699c79083813takashi * 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.
3c13a815670b54d1c17bf02954f7d2b066cde95cndtypedef struct {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void *create_echo_server_config(apr_pool_t *p, server_rec *s)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe EchoConfig *pConfig = apr_pcalloc(p, sizeof *pConfig);
af84459fbf938e508fd10b01cb8d699c79083813takashistatic const char *echo_on(cmd_parms *cmd, void *dummy, int arg)
af84459fbf938e508fd10b01cb8d699c79083813takashi EchoConfig *pConfig = ap_get_module_config(cmd->server->module_config,
af84459fbf938e508fd10b01cb8d699c79083813takashistatic apr_status_t brigade_peek(apr_bucket_brigade *bbIn,
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen /* compensate for NULL */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe while ((b != APR_BRIGADE_SENTINEL(bbIn)) && (readbytes < bufflen)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if ((rv = apr_bucket_read(b, &str, &len, APR_NONBLOCK_READ))
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* initial pass only, please - in the name of efficiency */
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen ap_get_remote_host(c, c->base_server->lookup_defaults,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_cpystrn(ws->vhost, c->base_server->server_hostname,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Deliberate trailing space - filling in string on WRITE passes */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_cpystrn(ws->request, "ECHO ", sizeof(ws->request));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* each subsequent WRITE pass, let's update what we echoed */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe brigade_peek(last_echoed, ws->request + sizeof("ECHO ") - 1,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe EchoConfig *pConfig = ap_get_module_config(c->base_server->module_config,
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh update_echo_child_status(c->sbh, SERVER_BUSY_READ, c, NULL);
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh for ( ; ; ) {
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh /* Get a single line of input from the client */
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (((rv = ap_get_brigade(c->input_filters, bb, AP_MODE_GETLINE,
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (!APR_STATUS_IS_EOF(rv) && ! APR_STATUS_IS_TIMEUP(rv))
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01611)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "ProtocolEcho: Failure reading from %s",
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Something horribly wrong happened. Someone didn't block! */
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01612)
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh "ProtocolEcho: Error - read empty brigade from %s!",
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout);
af84459fbf938e508fd10b01cb8d699c79083813takashi update_echo_child_status(c->sbh, SERVER_BUSY_WRITE, NULL, bb);
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen /* Make sure the data is flushed to the client */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server, APLOGNO(01613)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "ProtocolEcho: Failure writing to %s",
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic /* Announce our intent to loop */
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic update_echo_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, NULL, NULL);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic update_echo_child_status(c->sbh, SERVER_CLOSING, c, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe AP_INIT_FLAG("ProtocolEcho", echo_on, NULL, RSRC_CONF,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "Run an echo server on this host"),
4bebf996eb7002ebfe897d46a0e0572390604a77nd ap_hook_process_connection(process_echo_connection, NULL, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe create_echo_server_config, /* create per-server config structure */