/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MOD_PROXY_H
#define MOD_PROXY_H
/**
* @file mod_proxy.h
* @brief Proxy Extension Module for Apache
*
* @defgroup MOD_PROXY mod_proxy
* @ingroup APACHE_MODS
* @{
*/
#include "apr_hooks.h"
#include "apr_optional.h"
#include "apr.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_md5.h"
#include "apr_network_io.h"
#include "apr_pools.h"
#include "apr_strings.h"
#include "apr_uri.h"
#include "apr_date.h"
#include "apr_strmatch.h"
#include "apr_fnmatch.h"
#include "apr_reslist.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "apr_uuid.h"
#include "util_mutex.h"
#include "apr_global_mutex.h"
#include "apr_thread_mutex.h"
#include "httpd.h"
#include "http_config.h"
#include "ap_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_main.h"
#include "http_log.h"
#include "http_connection.h"
#include "util_filter.h"
#include "util_ebcdic.h"
#include "ap_provider.h"
#include "ap_slotmem.h"
#endif
#endif
/* for proxy_canonenc() */
enum enctype {
};
#else /*APR_CHARSET_EBCDIC*/
#endif /*APR_CHARSET_EBCDIC*/
/* default Max-Forwards header setting */
/* Set this to -1, which complies with RFC2616 by not setting
* max-forwards if the client didn't send it to us.
*/
/* static information about a remote proxy */
struct proxy_remote {
};
struct proxy_alias {
const char *real;
const char *fake;
unsigned int flags;
};
struct dirconn_entry {
char *name;
};
struct noproxy_entry {
const char *name;
};
typedef struct {
const char *id;
enum {
long maxfwd;
enum {
enum {
typedef struct {
const char *p; /* The path */
ap_regex_t *r; /* Is this a regex? */
/* FIXME
* ProxyPassReverse and friends are documented as working inside
* <Location>. But in fact they never have done in the case of
* more than one <Location>, because the server_conf can't see it.
* We need to move them to the per-dir config.
* Discussed in February 2005:
*/
signed char interpolate_env;
/**
* the following setting masks the error page
* returned from the 'proxied server' and just
* forwards the status code upwards.
* This allows the main server (us) to generate
* the error page, (so it will look like a error
* returned from the rest of the system
*/
/** Named back references */
/* if we interpolate env vars per-request, we'll need a per-request
* copy of the reverse proxy config
*/
typedef struct {
typedef struct {
request_rec *r; /* Request record of the backend request
* that is used over the backend connection. */
const char *hostname;
* filter chain or not */
typedef struct {
/* Connection pool */
struct proxy_conn_pool {
};
/* Keep below in sync with proxy_util.c! */
/* worker status bits */
/* worker status flags */
/* NOTE: these check the shared status */
/* default worker retry timeout in seconds */
/* Some max char string sizes, for shm fields */
#define PROXY_COPY_CONF_PARAMS(w, c) \
do { \
(w)->s->timeout_set = (c)->timeout_set; \
(w)->s->recv_buffer_size = (c)->recv_buffer_size; \
(w)->s->recv_buffer_size_set = (c)->recv_buffer_size_set; \
(w)->s->io_buffer_size = (c)->io_buffer_size; \
(w)->s->io_buffer_size_set = (c)->io_buffer_size_set; \
} while (0)
/* use 2 hashes */
typedef struct {
unsigned int def;
unsigned int fnv;
} proxy_hashes ;
/* Runtime worker status informations. Shared in scoreboard */
typedef struct {
enum {
* may be available while exceeding the soft limit */
apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
/* Worker configuration */
struct proxy_worker {
proxy_worker_shared *s; /* Shared data */
};
/*
* Time to wait (in microseconds) to find out if more data is currently
* available at the backend.
*/
typedef struct {
struct proxy_balancer {
proxy_balancer_shared *s; /* Shared data */
};
struct proxy_balancer_method {
request_rec *r);
};
#define PROXY_THREAD_LOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_lock((x)->tmutex) : APR_SUCCESS)
#define PROXY_THREAD_UNLOCK(x) ( (x) && (x)->tmutex ? apr_thread_mutex_unlock((x)->tmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_LOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_lock((x)->gmutex) : APR_SUCCESS)
#define PROXY_GLOBAL_UNLOCK(x) ( (x) && (x)->gmutex ? apr_global_mutex_unlock((x)->gmutex) : APR_SUCCESS)
/* hooks */
/* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
* PROXY_DECLARE_DATA with appropriate export and import tags for the platform
*/
#if !defined(WIN32)
#define PROXY_DECLARE_DATA
#elif defined(PROXY_DECLARE_STATIC)
#define PROXY_DECLARE_DATA
#elif defined(PROXY_DECLARE_EXPORT)
#else
#endif
char *url))
/**
* Let modules perform processing when the connection to the origin is being
* detached from the request.
* @param r The client request
* @param backend The proxy representation of the backend connection
*/
/**
* pre request hook.
* It will return the most suitable worker at the moment
* and coresponding balancer.
* and then the scheme_handler is called.
*
*/
request_rec *r,
/**
* post request hook.
* It is called after request for updating runtime balancer status.
*/
/**
* request status hook
* It is called after all proxy processing has been done. This gives other
* modules a chance to create default content on failure, for example
*/
(int *status, request_rec *r))
/* proxy_util.c */
PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
* configuration.
* @param r request
* @param conf server configuration
* @param hostname hostname from request URI
* @param addr resolved address of hostname, or NULL if not known
* @return OK on success, or else an errro
*/
/* DEPRECATED (will be replaced with ap_proxy_connect_backend */
PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, request_rec *);
request_rec *r);
PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
/* Header mapping functions, and a typedef of their signature */
PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
#if !defined(WIN32)
proxy_dir_conf *, const char *);
#elif defined(PROXY_DECLARE_STATIC)
proxy_dir_conf *, const char *);
#elif defined(PROXY_DECLARE_EXPORT)
typedef __declspec(dllexport) const char *
proxy_dir_conf *, const char *);
#else
typedef __declspec(dllimport) const char *
proxy_dir_conf *, const char *);
#endif
/* Connection pool API */
/**
* Return the user-land, UDS aware worker name
* @param p memory pool used for displaying worker name
* @param worker the worker
* @return name
*/
/**
* Get the worker from proxy configuration
* @param p memory pool used for finding worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
* @param url url to find the worker from
* @return proxy_worker or NULL if not found
*/
const char *url);
/**
* Define and Allocate space for the worker to proxy configuration
* @param p memory pool to allocate worker from
* @param worker the new worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
* @param url url containing worker name
* @param do_malloc true if shared struct should be malloced
* @return error message or NULL if successful (*worker is new worker)
*/
const char *url,
int do_malloc);
/**
* Define and Allocate space for the ap_strcmp_match()able worker to proxy
* configuration.
* @param p memory pool to allocate worker from
* @param worker the new worker
* @param balancer the balancer that the worker belongs to
* @param conf current proxy server configuration
* @param url url containing worker name (produces match pattern)
* @param do_malloc true if shared struct should be malloced
* @return error message or NULL if successful (*worker is new worker)
*/
const char *url,
int do_malloc);
/**
* Share a defined proxy worker via shm
* @param worker worker to be shared
* @param shm location of shared info
* @param i index into shm
* @return APR_SUCCESS or error code
*/
int i);
/**
* Initialize the worker by setting up worker connection pool and mutex
* @param worker worker to initialize
* @param s current server record
* @param p memory pool used for mutex and connection pool
* @return APR_SUCCESS or error code
*/
server_rec *s,
apr_pool_t *p);
/**
* Verifies valid balancer name (eg: balancer://foo)
* @param name name to test
* @param i number of chars to test; 0 for all.
*/
/**
* Get the balancer from proxy configuration
* @param p memory pool used for temporary storage while finding balancer
* @param conf current proxy server configuration
* @param url url to find the worker from; must have balancer:// prefix
* @param careactive true if we care if the balancer is active or not
* @return proxy_balancer or NULL if not found
*/
const char *url,
int careactive);
/**
* Update the balancer's vhost related fields
* @param p memory pool used for temporary storage while finding balancer
* @param balancer balancer to be updated
* @param url url to find vhost info
* @return error string or NULL if OK
*/
const char *url);
/**
* Define and Allocate space for the balancer to proxy configuration
* @param p memory pool to allocate balancer from
* @param balancer the new balancer
* @param conf current proxy server configuration
* @param url url containing balancer name
* @param do_malloc true if shared struct should be malloced
* @return error message or NULL if successfull
*/
const char *url,
const char *alias,
int do_malloc);
/**
* Share a defined proxy balancer via shm
* @param balancer balancer to be shared
* @param shm location of shared info
* @param i index into shm
* @return APR_SUCCESS or error code
*/
int i);
/**
* Initialize the balancer as needed
* @param balancer balancer to initialize
* @param s current server record
* @param p memory pool used for mutex and connection pool
* @return APR_SUCCESS or error code
*/
server_rec *s,
apr_pool_t *p);
/**
* Find the shm of the worker as needed
* @param storage slotmem provider
* @param slot slotmem instance
* @param worker worker to find
* @param index pointer to index within slotmem of worker
* @return pointer to shm of worker, or NULL
*/
unsigned int *index);
/**
* Find the shm of the balancer as needed
* @param storage slotmem provider
* @param slot slotmem instance
* @param balancer balancer of shm to find
* @param index pointer to index within slotmem of balancer
* @return pointer to shm of balancer, or NULL
*/
unsigned int *index);
/**
* @param worker worker used for processing request
* @param balancer balancer used for processing request
* @param r current request
* @param conf current proxy server configuration
* @param url request url that balancer can rewrite.
* @return OK or HTTP_XXX error
* @note It calls balancer pre_request hook if the url starts with balancer://
* The balancer then rewrites the url to particular worker, like http://host:port
*/
request_rec *r,
char **url);
/**
* Post request worker and balancer cleanup
* @param worker worker used for processing request
* @param balancer balancer used for processing request
* @param r current request
* @param conf current proxy server configuration
* @return OK or HTTP_XXX error
* @note Whenever the pre_request is called, the post_request has to be
* called too.
*/
request_rec *r,
/**
* Determine backend hostname and port
* @param p memory pool used for processing
* @param r current request
* @param conf current proxy server configuration
* @param worker worker used for processing request
* @param conn proxy connection struct
* @param uri processed uri
* @param url request url
* @param proxyname are we connecting directly or via a proxy
* @param proxyport proxy host port
* @param server_portstr Via headers server port, must be non-NULL
* @param server_portstr_size size of the server_portstr buffer; must
* be at least one, even if the protocol doesn't use this
* @return OK or HTTP_XXX error
*/
char **url,
const char *proxyname,
char *server_portstr,
int server_portstr_size);
/**
* Mark a worker for retry
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param worker worker used for retrying
* @param s current server record
* @return OK if marked for retry, DECLINED otherwise
* @note The error status of the worker will cleared if the retry interval has
* elapsed since the last error.
*/
/**
* Acquire a connection from worker connection pool
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param worker worker used for obtaining connection
* @param s current server record
* @return OK or HTTP_XXX error
* @note If the connection limit has been reached, the function will
* block until a connection becomes available or the timeout has
* elapsed.
*/
server_rec *s);
/**
* Release a connection back to worker connection pool
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param s current server record
* @return OK or HTTP_XXX error
* @note The connection will be closed if conn->close_on_release is set
*/
server_rec *s);
/**
* Make a connection to the backend
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param worker connection worker
* @param s current server record
* @return OK or HTTP_XXX error
* @note In case the socket already exists for conn, just check the link
* status.
*/
server_rec *s);
/**
* Make a connection to a Unix Domain Socket (UDS) path
* @param sock UDS to connect
* @param uds_path UDS path to connect to
* @param p pool to make the sock addr
* @return APR_SUCCESS or error status
*/
const char *uds_path,
apr_pool_t *p);
/**
* Make a connection record for backend connection
* @param proxy_function calling proxy scheme (http, ajp, ...)
* @param conn acquired connection
* @param c client connection record
* @param s current server record
* @return OK or HTTP_XXX error
* @note The function will return immediately if conn->connection
* is already set,
*/
conn_rec *c, server_rec *s);
/**
* Determine if proxy connection can potentially be reused at the
* end of this request.
* @param conn proxy connection
* @return non-zero if reusable, 0 otherwise
* @note Even if this function returns non-zero, the connection may
* be subsequently marked for closure.
*/
/**
* Signal the upstream chain that the connection to the backend broke in the
* middle of the response. This is done by sending an error bucket with
* status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
* @param r current request record of client request
* @param brigade The brigade that is sent through the output filter chain
* @deprecated To be removed in v2.6.
*/
/**
* Return a hash based on the passed string
* @param str string to produce hash from
* @param method hashing method to use
* @return hash as unsigned int
*/
/**
* @param c flag
* @param set set or unset bit
* @param w worker to use
* @return APR_SUCCESS if valid flag
*/
/**
* Create readable representation of worker status bitfield
* @param p pool
* @param w worker to use
* @return string representation of status
*/
/**
* Sync balancer and workers based on any updates w/i shm
* @param s server rec
* @param conf config
* @return APR_SUCCESS if all goes well
*/
server_rec *s,
/**
* Find the matched alias for this request and setup for proxy handler
* @param r request
* @param ent proxy_alias record
* @param dconf per-dir config or NULL
* @return DECLINED, DONE or OK if matched
*/
struct proxy_alias *ent,
/**
* Create a HTTP request header brigade, old_cl_val and old_te_val as required.
* @param p pool
* @param r request
* @param p_conn proxy connection rec
* @param worker selected worker
* @param conf per-server proxy config
* @param uri uri
* @param url url
* @param server_portstr port as string
* @param old_cl_val stored old content-len val
* @param old_te_val stored old TE val
* @return OK or HTTP_EXPECTATION_FAILED
*/
request_rec *r,
char *url, char *server_portstr,
char **old_cl_val,
char **old_te_val);
/**
* @param bucket_alloc bucket allocator
* @param r request
* @param p_conn proxy connection
* @param origin connection rec of origin
* @param bb brigade to send to origin
* @param flush flush
* @return status (OK)
*/
int flush);
/**
* Clear the headers referenced by the Connection header from the given
* table, and remove the Connection header.
* @param r request
* @param headers table of headers to clear
* @return 1 if "close" was present, 0 otherwise.
*/
/**
* @param socket socket to test
*/
/* The number of dynamic workers that can be added when reconfiguring.
* If this limit is reached you must stop and restart the server.
*/
/**
* Calculate maximum number of workers in scoreboard.
* @return number of workers to allocate in the scoreboard
*/
int ap_proxy_lb_workers(void);
/**
* Return the port number of a known scheme (eg: http -> 80).
* @param scheme scheme to test
* @return port number or 0 if unknown
*/
/**
* Strip a unix domain socket (UDS) prefix from the input URL
* @param p pool to allocate result from
* @param url a URL potentially prefixed with a UDS path
* @return URL with the UDS prefix removed
*/
#endif /*MOD_PROXY_H*/
/** @} */