1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
63 * Main include file for the Apache proxy
68 Also note numerous FIXMEs and CHECKMEs which should be eliminated.
70 This code is once again experimental!
74 1. Make it completely work (for FTP too)
78 Chuck Murcko <chuck@topsail.org> 02-06-01
84 #include "apr_hooks.h"
86 #include "apr_compat.h"
88 #include "apr_strings.h"
89 #include "apr_buckets.h"
91 #include "apr_pools.h"
92 #include "apr_strings.h"
97 #include "http_config.h"
98 #include "ap_config.h"
99 #include "http_core.h"
100 #include "http_protocol.h"
101 #include "http_request.h"
102 #include "http_vhost.h"
103 #include "http_main.h"
104 #include "http_log.h"
105 #include "http_connection.h"
106 #include "util_filter.h"
107 #include "mod_core.h"
113 #if APR_HAVE_SYS_SOCKET_H
114 #include <sys/socket.h>
116 #if APR_HAVE_NETINET_IN_H
117 #include <netinet/in.h>
119 #if APR_HAVE_ARPA_INET_H
120 #include <arpa/inet.h>
123 /* for proxy_canonenc() */
125 enc_path, enc_search, enc_user, enc_fpath, enc_parm
128 #if APR_CHARSET_EBCDIC
130 #else /*APR_CHARSET_EBCDIC*/
131 #define CRLF "\015\012"
132 #endif /*APR_CHARSET_EBCDIC*/
134 /* default Max-Forwards header setting */
135 #define DEFAULT_MAX_FORWARDS 10
137 /* static information about a remote proxy */
138 struct proxy_remote {
139 const char *scheme; /* the schemes handled by this proxy, or '*' */
140 const char *protocol; /* the scheme used to talk to this proxy */
141 const char *hostname; /* the hostname of this proxy */
142 int port; /* the port for this proxy */
150 struct dirconn_entry {
152 struct in_addr addr, mask;
153 struct hostent *hostentry;
154 int (*matcher) (struct dirconn_entry * This, request_rec *r);
157 struct noproxy_entry {
159 struct apr_sockaddr_t *addr;
163 apr_array_header_t *proxies;
164 apr_array_header_t *aliases;
165 apr_array_header_t *raliases;
166 apr_array_header_t *noproxies;
167 apr_array_header_t *dirconn;
168 apr_array_header_t *allowed_connect_ports;
169 const char *domain; /* domain name to use in absence of a domain name in the request */
170 int req; /* true if proxy requests are enabled */
177 } viaopt; /* how to deal with proxy Via: headers */
179 size_t recv_buffer_size;
180 char recv_buffer_size_set;
185 struct per_thread_data {
186 struct hostent hpbuf;
192 conn_rec *connection;
198 float cache_completion; /* completion percentage */
199 int content_length; /* length of the content */
205 /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and
206 * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
209 #define PROXY_DECLARE(type) type
210 #define PROXY_DECLARE_NONSTD(type) type
211 #define PROXY_DECLARE_DATA
212 #elif defined(PROXY_DECLARE_STATIC)
213 #define PROXY_DECLARE(type) type __stdcall
214 #define PROXY_DECLARE_NONSTD(type) type
215 #define PROXY_DECLARE_DATA
216 #elif defined(PROXY_DECLARE_EXPORT)
217 #define PROXY_DECLARE(type) __declspec(dllexport) type __stdcall
218 #define PROXY_DECLARE_NONSTD(type) __declspec(dllexport) type
219 #define PROXY_DECLARE_DATA __declspec(dllexport)
221 #define PROXY_DECLARE(type) __declspec(dllimport) type __stdcall
222 #define PROXY_DECLARE_NONSTD(type) __declspec(dllimport) type
223 #define PROXY_DECLARE_DATA __declspec(dllimport)
226 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r,
227 proxy_server_conf *conf, char *url,
228 const char *proxyhost, apr_port_t proxyport))
229 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r,
234 PROXY_DECLARE(request_rec *)make_fake_req(conn_rec *c, request_rec *r);
235 PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
236 PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
237 PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
239 PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
240 char **passwordp, char **hostp, apr_port_t *port);
241 PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
242 PROXY_DECLARE(apr_table_t *)ap_proxy_read_headers(request_rec *r, request_rec *rp, char *buffer, int size, conn_rec *c);
243 PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
244 PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
245 PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
246 PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
247 PROXY_DECLARE(const char *)ap_proxy_host2addr(const char *host, struct hostent *reqhp);
248 PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
249 PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
250 PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
251 PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
252 PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
253 PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
254 PROXY_DECLARE(int) ap_proxy_pre_http_connection(conn_rec *c, request_rec *r);
255 PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
256 PROXY_DECLARE(void) ap_proxy_reset_output_filters(conn_rec *c);
259 #endif /*MOD_PROXY_H*/