proxy_util.c revision 87396d56ac610785156706de7f0d3009317d906c
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* Copyright 1999-2004 The Apache Software Foundation
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Licensed under the Apache License, Version 2.0 (the "License");
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * you may not use this file except in compliance with the License.
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * You may obtain a copy of the License at
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * http://www.apache.org/licenses/LICENSE-2.0
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Unless required by applicable law or agreed to in writing, software
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * distributed under the License is distributed on an "AS IS" BASIS,
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * See the License for the specific language governing permissions and
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * limitations under the License.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* Utility routines for Apache proxy */
79e28be65fd0bc65adf266d5ae4f6deb92546bf7Christian Maeder#define apr_socket_create apr_socket_create_ex
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder/* Global balancer counter */
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maederstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maederstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maederstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maederstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r);
89026e63176e6e40c7be1bbc542326f0d29d8108Christian MaederAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, create_req,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder (request_rec *r, request_rec *pr), (r, pr),
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder/* already called in the knowledge that the characters are hex digits */
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian MaederPROXY_DECLARE(int) ap_proxy_hex2c(const char *x)
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder#else /*APR_CHARSET_EBCDIC*/
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder /* we assume that the hex value refers to an ASCII character
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * so convert to EBCDIC so that it makes sense locally;
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * client specifies %20 in URL to refer to a space char;
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * at this point we're called with EBCDIC "20"; after turning
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder * represents an ASCII char and convert 0x20 to EBCDIC, yielding
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder#endif /*APR_CHARSET_EBCDIC*/
79e28be65fd0bc65adf266d5ae4f6deb92546bf7Christian MaederPROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x)
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder#else /*APR_CHARSET_EBCDIC*/
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder static const char ntoa[] = { "0123456789ABCDEF" };
5b55761e0df088c5b41183fb83106bfd02a61fa2Christian Maeder#endif /*APR_CHARSET_EBCDIC*/
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * canonicalise a URL-encoded string
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Convert a URL-encoded string to canonical form.
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * It decodes characters which need not be encoded,
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * and encodes those which must be encoded, and does not touch
89026e63176e6e40c7be1bbc542326f0d29d8108Christian Maeder * those which must not be touched.
89026e63176e6e40c7be1bbc542326f0d29d8108Christian MaederPROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder char *allowed; /* characters which should not be encoded */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder char *reserved; /* characters which much not be en/de-coded */
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder/* N.B. in addition to :@&=, this allows ';' in an http path
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * and '?' in an ftp path -- this may be revised
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder * Also, it makes a '+' character in a search string reserved, as
8ab0f7627987d45eb3fe36845a91694977ca5cdbChristian Maeder * it may be form-encoded. (Although RFC 1738 doesn't allow this -
8ab0f7627987d45eb3fe36845a91694977ca5cdbChristian Maeder * it only permits ; / ? : @ = & as reserved chars.)
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder else if (t == enc_user)
57dc8a87418e235e3d0621fb90728054044a9ef9Christian Maeder else /* if (t == enc_parm) */
else if (t == enc_search)
for (i = 0, j = 0; i < len; i++, j++) {
ch = x[i];
y[j] = ch;
return NULL;
y[j] = ch;
PROXY_DECLARE(char *)
return NULL;
PROXY_DECLARE(const char *)
return rp;
int len, i;
if (p != NULL) {
i = p - list;
while (apr_isspace(*p));
list = p;
int len, i;
if (p != NULL) {
i = p - list;
while (apr_isspace(*p));
if (new)
list = p;
return new;
int i, ch;
ch = x[i];
int i, ch;
return statuscode;
return r->hostname;
return NULL;
url = apr_pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
int i, quads;
long bits;
char *tmp;
char *tmp;
++addr;
--quads;
/* "IP Address should be given in dotted-quad form, optionally followed by a netmask (e.g., 192.168.111.0/24)"; */
#if DEBUGGING
#if DEBUGGING
!= APR_SUCCESS) {
#if DEBUGGING
host);
while (reqaddr) {
#if DEBUGGING
#if DEBUGGING
--d_len;
--h_len;
int h2_len;
int h1_len;
while (addr) {
--h2_len;
--h1_len;
return HTTP_FORBIDDEN;
while (conf_addr) {
while (uri_addr) {
char *conf_ip;
char *uri_ip;
return HTTP_FORBIDDEN;
return OK;
return OK;
* ap_rgetline() in protocol.c. Deprecate this function and use ap_rgetline()
apr_bucket *e;
char *response;
int found = 0;
buff[0] = 0;
*eos = 0;
while (!found) {
return rv;
while (!found) {
return APR_ECONNABORTED;
if (APR_BUCKET_IS_EOS(e)) {
return rv;
if (len > 0) {
return APR_SUCCESS;
if (!initial) {
count++;
const char *url)
return NULL;
return balancer;
balancer++;
return NULL;
apr_pool_t *p,
const char *url)
#if APR_HAS_THREADS
return NULL;
const char *url)
return NULL;
return worker;
worker++;
return NULL;
#if APR_HAS_THREADS
return APR_SUCCESS;
apr_pool_t *p,
const char *url)
int port;
if (q != NULL) {
return NULL;
return worker;
PROXY_DECLARE(void)
int mpm_daemons;
++lb_workers;
request_rec *r,
int access_status;
if (*worker) {
return access_status;
request_rec *r,
int access_status;
if (balancer)
return access_status;
const char *proxy_function,
const char *backend_name,
server_rec *s,
apr_pool_t *p)
int connected = 0;
int loglevel;
return APR_SUCCESS;
#if APR_HAS_THREADS
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
#if APR_HAS_THREADS
int mpm_threads;
#if (APR_MAJOR_VERSION > 0)
return rv;
server_rec *s)
return OK;
return DECLINED;
return OK;
server_rec *s)
return HTTP_SERVICE_UNAVAILABLE;
#if APR_HAS_THREADS
return HTTP_SERVICE_UNAVAILABLE;
return OK;
server_rec *s)
return OK;
PROXY_DECLARE(int)
char **url,
const char *proxyname,
char *server_portstr,
int server_portstr_size)
int server_port;
NULL));
if (proxyname) {
return OK;
server_rec *s)
int connected = 0;
int loglevel;
conn_rec *c,
server_rec *s)
c->bucket_alloc);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
return lb_workers_limit;