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