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