http_connection.h revision b44ddab21bd6e44ba3c03f7ae8ed08dd23b68b48
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/* Licensed to the Apache Software Foundation (ASF) under one or more
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * contributor license agreements. See the NOTICE file distributed with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * this work for additional information regarding copyright ownership.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The ASF licenses this file to You under the Apache License, Version 2.0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the "License"); you may not use this file except in compliance with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the License. You may obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * http://www.apache.org/licenses/LICENSE-2.0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Unless required by applicable law or agreed to in writing, software
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * distributed under the License is distributed on an "AS IS" BASIS,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing permissions and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @file http_connection.h
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @brief Apache connection library
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @defgroup APACHE_CORE_CONNECTION Connection Library
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @ingroup APACHE_CORE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifndef APACHE_HTTP_CONNECTION_H
e6c3a72a023407f5d1fface64356e1cc81f1af31Phill Cunnington#define APACHE_HTTP_CONNECTION_H
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#include "apr_network_io.h"
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington#include "apr_buckets.h"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef __cplusplus
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Maddenextern "C" {
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden#endif
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden/**
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * @file http_connection.h
f48118365a7f4f1240516dbe66e47b24a896ff16Craig McDonnell * @brief Apache connection library
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden */
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden/**
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * This is the protocol module driver. This calls all of the
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * pre-connection and connection hooks for all protocol modules.
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * @param c The connection on which the request is read
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * @param csd The mechanism on which this connection is to be read.
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * Most times this will be a socket, but it is up to the module
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * that accepts the request to determine the exact type.
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden */
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil MaddenAP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, void *csd);
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden/**
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * Flushes all remain data in the client send buffer
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * @param c The connection to flush
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill CunningtonAP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/**
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * This function is responsible for the following cases:
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * <pre>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * we now proceed to read from the client until we get EOF, or until
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * MAX_SECS_TO_LINGER has passed. the reasons for doing this are
a82d04bc19fee9d5e34b41ccd7641da1f62ab634Neil Madden * documented in a draft:
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-connection-00.txt
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * in a nutshell -- if we don't make this effort we risk causing
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * TCP RST packets to be sent which can tear down a connection before
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * all the response data has been sent to the client.
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * </pre>
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * @param c The connection we are closing
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill CunningtonAP_DECLARE(void) ap_lingering_close(conn_rec *c);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill CunningtonAP_DECLARE(int) ap_start_lingering_close(conn_rec *c);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/* Hooks */
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden/**
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * create_connection is a RUN_FIRST hook which allows modules to create
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * connections. In general, you should not install filters with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * create_connection hook. If you require vhost configuration information
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to make filter installation decisions, you must use the pre_connection
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * or install_network_transport hook. This hook should close the connection
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if it encounters a fatal error condition.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param p The pool from which to allocate the connection record
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param server The server record to create the connection too.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param csd The socket that has been accepted
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param conn_id A unique identifier for this connection. The ID only
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * needs to be unique at that time, not forever.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param sbh A handle to scoreboard information for this connection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param alloc The bucket allocator to use for all bucket/brigade creations
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return An allocated connection record or NULL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill CunningtonAP_DECLARE_HOOK(conn_rec *, create_connection,
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington (apr_pool_t *p, server_rec *server, apr_socket_t *csd,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long conn_id, void *sbh, apr_bucket_alloc_t *alloc))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This hook gives protocol modules an opportunity to set everything up
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * before calling the protocol handler. All pre-connection hooks are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * run until one returns something other than ok or decline
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * @param c The connection on which the request has been received.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param csd The mechanism on which this connection is to be read.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Most times this will be a socket, but it is up to the module
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * that accepts the request to determine the exact type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return OK or DECLINED
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterAP_DECLARE_HOOK(int,pre_connection,(conn_rec *c, void *csd))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * This hook implements different protocols. After a connection has been
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * established, the protocol module must read and serve the request. This
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * function does that for each protocol module. The first protocol module
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to handle the request is the last module run.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param c The connection on which the request has been received.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return OK or DECLINED
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterAP_DECLARE_HOOK(int,process_connection,(conn_rec *c))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** End Of Connection (EOC) bucket */
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterAP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eoc;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Determine if a bucket is an End Of Connection (EOC) bucket
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param e The bucket to inspect
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true or false
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#define AP_BUCKET_IS_EOC(e) (e->type == &ap_bucket_type_eoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Make the bucket passed in an End Of Connection (EOC) bucket
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param b The bucket to make into an EOC bucket
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The new bucket, or NULL if allocation failed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterAP_DECLARE(apr_bucket *) ap_bucket_eoc_make(apr_bucket *b);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Create a bucket referring to an End Of Connection (EOC). This indicates
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * that the connection will be closed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param list The freelist from which this bucket should be allocated
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The new bucket, or NULL if allocation failed
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan FosterAP_DECLARE(apr_bucket *) ap_bucket_eoc_create(apr_bucket_alloc_t *list);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#ifdef __cplusplus
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#endif /* !APACHE_HTTP_REQUEST_H */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** @} */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster