proxy_util.c revision 3ff68b9ee78262779dbedf791576d35fdd229f7b
f743002678eb67b99bbc29fee116b65d9530fec0wrowe/* Licensed to the Apache Software Foundation (ASF) under one or more
80833bb9a1bf25dcf19e814438a4b311d2e1f4cffuankg * contributor license agreements. See the NOTICE file distributed with
5c43d2fb853f84497b5ece2d414ef9484aa87e5fsf * this work for additional information regarding copyright ownership.
9811aed12bbc71783d2e544ccb5fecd193843eadsf * The ASF licenses this file to You under the Apache License, Version 2.0
9811aed12bbc71783d2e544ccb5fecd193843eadsf * (the "License"); you may not use this file except in compliance with
9811aed12bbc71783d2e544ccb5fecd193843eadsf * the License. You may obtain a copy of the License at
e02ff627c1e63137247e20493f6ef44b3bb1a095sf * Unless required by applicable law or agreed to in writing, software
e02ff627c1e63137247e20493f6ef44b3bb1a095sf * distributed under the License is distributed on an "AS IS" BASIS,
e02ff627c1e63137247e20493f6ef44b3bb1a095sf * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39f33ff7759ccee97f161f789b0cab07e735a6bcjailletc * See the License for the specific language governing permissions and
39f33ff7759ccee97f161f789b0cab07e735a6bcjailletc * limitations under the License.
1366443dc565c33e7b449ae428bbfc4c86f33935drh/* Utility routines for Apache proxy */
9e430d18dde58791589bd699416c8319560dd067jim/* Global balancer counter */
9e430d18dde58791589bd699416c8319560dd067jimstatic int lb_workers_limit = 0;
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csfstatic int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
584a85dd4047e38d3ed3a29b6662fcc9d100ae4csfstatic int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sfstatic int proxy_match_hostname(struct dirconn_entry *This, request_rec *r);
f21e9e3d0bfb7a507ecc5bc963f2159d693503d1sfstatic int proxy_match_word(struct dirconn_entry *This, request_rec *r);
f6b9c755a0b793e8a3a3aebd327ca20a86478117sfAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, create_req,
132ee6ac1c26d6e8953836316ba50734eefab47bsf/* already called in the knowledge that the characters are hex digits */
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton#else /*APR_CHARSET_EBCDIC*/
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton * we assume that the hex value refers to an ASCII character
70caa242e6b90e0d6f0fabb56b8c5c2fb51717b3jorton * so convert to EBCDIC so that it makes sense locally;
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh * client specifies %20 in URL to refer to a space char;
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh * at this point we're called with EBCDIC "20"; after turning
74e7a30182af5e68f14ccb8d57918b22b982db8bhumbedooh * EBCDIC "20" into binary 0x20, we then need to assume that 0x20
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh * represents an ASCII char and convert 0x20 to EBCDIC, yielding
91654e263480f0fdc2a03d782ff23f8dad07cf79humbedooh#endif /*APR_CHARSET_EBCDIC*/
79c5787b92ac5f0e1cc82393816c77a006399316trawick x[0] = '%';
79c5787b92ac5f0e1cc82393816c77a006399316trawick if (i >= 10) {
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton if (i >= 10) {
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton#else /*APR_CHARSET_EBCDIC*/
53e9b27aba029b18be814df40bcf6f0428771d1efuankg x[0] = '%';
ca61ccd0c306c2c72df153688ba1b49f3eceed80sf#endif /*APR_CHARSET_EBCDIC*/
e6dd71992459d05a676b98b7963423dc5dc1e24aminfrin * canonicalise a URL-encoded string
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin * Convert a URL-encoded string to canonical form.
23f1535d6a60817d2846bac0aea230ea475d7dccminfrin * It decodes characters which need not be encoded,
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung * and encodes those which must be encoded, and does not touch
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung * those which must not be touched.
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjungPROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len,
ec7520b24cd80d34d82bbcaca153cbb23cc04bc0rjung int i, j, ch;
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick char *allowed; /* characters which should not be encoded */
0827cb14e550f6f65018431c22c2c913631c8f25kbrand char *reserved; /* characters which much not be en/de-coded */
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick * N.B. in addition to :@&=, this allows ';' in an http path
cfa64348224b66dd1c9979b809406c4d15b1c137fielding * and '?' in an ftp path -- this may be revised
cfa64348224b66dd1c9979b809406c4d15b1c137fielding * Also, it makes a '+' character in a search string reserved, as
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim * it may be form-encoded. (Although RFC 1738 doesn't allow this -
cfa64348224b66dd1c9979b809406c4d15b1c137fielding * it only permits ; / ? : @ = & as reserved chars.)
else if (t == enc_search) {
else if (t == enc_user) {
else if (t == enc_fpath) {
if (t == enc_path) {
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
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)) {
(const char **)&response,
&len,
APR_BLOCK_READ))) {
return rv;
if (len > 0) {
return APR_SUCCESS;
if (!initial) {
count++;
return url;
return url;
&proxy_module);
const char *pathp;
const char *domainp;
int ddiff = 0;
int pdiff = 0;
char *ret;
return str;
if (newpath) {
if (newdomain) {
if (newdomain) {
return ret;
const char *url)
return NULL;
return balancer;
balancer++;
return NULL;
apr_pool_t *p,
const char *url)
if (!lbmethod) {
#if APR_HAS_THREADS
return NULL;
const char *url)
int max_match = 0;
int url_length;
int worker_name_length;
char *url_copy;
return NULL;
char *pathstart;
worker++;
return max_worker;
#if APR_HAS_THREADS
return APR_SUCCESS;
apr_pool_t *p,
const char *url)
int rv;
#if APR_HAS_THREADS
return NULL;
return worker;
PROXY_DECLARE(void)
request_rec *r,
int access_status;
if (*worker) {
*url);
*url);
*url);
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;
#if APR_HAS_THREADS
return APR_SUCCESS;
#if APR_HAS_THREADS
return APR_SUCCESS;
return APR_SUCCESS;
server_rec *s)
if (ap_scoreboard_image) {
if (!score) {
if (!score) {
#if APR_HAS_THREADS
int mpm_threads;
return APR_SUCCESS;
#if APR_HAS_THREADS
#if (APR_MAJOR_VERSION > 0)
void *conn;
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;
#if APR_HAS_THREADS
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) {
if (proxyname) {
return HTTP_INTERNAL_SERVER_ERROR;
return OK;
#ifndef _MSC_VER
#define USE_ALTERNATE_IS_CONNECTED 0
int rc;
#ifdef _MSC_VER
if (rc == 0) {
#ifdef _MSC_VER
int nr;
server_rec *s)
int connected = 0;
int loglevel;
conn_rec *c,
server_rec *s)
int rc;
c->bucket_alloc);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return rc;
return OK;
int ap_proxy_lb_workers(void)
if (!lb_workers_limit)
return lb_workers_limit;
apr_bucket *e;
if (r->main)
c->bucket_alloc);