1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 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 Note that the Explain() stuff is not yet complete.
69 Also note numerous FIXMEs and CHECKMEs which should be eliminated.
71 If TESTING is set, then garbage collection doesn't delete ... probably a good
74 This code is once again experimental!
78 1. Make it completely work (for FTP too)
84 Chuck Murcko <chuck@topsail.org> 02-06-01
91 #include "apr_compat.h"
92 #include "apr_strings.h"
97 #if APR_HAVE_SYS_SOCKET_H
98 #include <sys/socket.h>
100 #if APR_HAVE_NETINET_IN_H
101 #include <netinet/in.h>
103 #if APR_HAVE_ARPA_INET_H
104 #include <arpa/inet.h>
108 #include "http_config.h"
109 #include "http_protocol.h"
110 #include "proxy_cache.h"
113 extern module AP_MODULE_DECLARE_DATA proxy_module;
116 /* for proxy_canonenc() */
118 enc_path, enc_search, enc_user, enc_fpath, enc_parm
121 #define HDR_APP (0) /* append header, for proxy_add_header() */
122 #define HDR_REP (1) /* replace header, for proxy_add_header() */
124 #if APR_CHARSET_EBCDIC
126 #else /*APR_CHARSET_EBCDIC*/
127 #define CRLF "\015\012"
128 #endif /*APR_CHARSET_EBCDIC*/
130 #define DEFAULT_FTP_DATA_PORT 20
131 #define DEFAULT_FTP_PORT 21
132 #define DEFAULT_GOPHER_PORT 70
133 #define DEFAULT_NNTP_PORT 119
134 #define DEFAULT_WAIS_PORT 210
135 #define DEFAULT_HTTPS_PORT 443
136 #define DEFAULT_SNEWS_PORT 563
137 #define DEFAULT_PROSPERO_PORT 1525 /* WARNING: conflict w/Oracle */
139 #define DEFAULT_CACHE_COMPLETION (0.9)
140 /* Some WWW schemes and their default ports; this is basically /etc/services */
141 struct proxy_services {
146 /* static information about a remote proxy */
147 struct proxy_remote {
148 const char *scheme; /* the schemes handled by this proxy, or '*' */
149 const char *protocol; /* the scheme used to talk to this proxy */
150 const char *hostname; /* the hostname of this proxy */
151 int port; /* the port for this proxy */
159 struct dirconn_entry {
161 struct in_addr addr, mask;
162 struct hostent *hostentry;
163 int (*matcher) (struct dirconn_entry * This, request_rec *r);
166 struct noproxy_entry {
171 struct nocache_entry {
177 apr_array_header_t *proxies;
178 apr_array_header_t *aliases;
179 apr_array_header_t *raliases;
180 apr_array_header_t *noproxies;
181 apr_array_header_t *dirconn;
182 apr_array_header_t *nocaches;
183 apr_array_header_t *allowed_connect_ports;
184 const char *domain; /* domain name to use in absence of a domain name in the request */
185 int req; /* true if proxy requests are enabled */
186 float cache_completion; /* Force cache completion after this point */
192 } viaopt; /* how to deal with proxy Via: headers */
193 size_t recv_buffer_size;
194 ap_cache_handle_t *cache;
197 struct per_thread_data {
198 struct hostent hpbuf;
204 float cache_completion; /* completion percentage */
205 int content_length; /* length of the content */
209 /* Function prototypes */
211 /* proxy_connect.c */
213 int ap_proxy_connect_handler(request_rec *r, char *url,
214 const char *proxyhost, int proxyport);
218 int ap_proxy_ftp_canon(request_rec *r, char *url);
219 int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url);
223 int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
225 int ap_proxy_http_handler(request_rec *r, char *url,
226 const char *proxyhost, int proxyport);
230 int ap_proxy_hex2c(const char *x);
231 void ap_proxy_c2hex(int ch, char *x);
232 char *ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
234 char *ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
235 char **passwordp, char **hostp, int *port);
236 const char *ap_proxy_date_canon(apr_pool_t *p, const char *x);
237 apr_table_t *ap_proxy_read_headers(request_rec *r, char *buffer, int size, conn_rec *c);
238 void ap_proxy_send_headers(request_rec *r, const char *respline, apr_table_t *hdrs);
239 int ap_proxy_liststr(const char *list, const char *val);
240 void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength);
241 int ap_proxy_hex2sec(const char *x);
242 void ap_proxy_sec2hex(int t, char *y);
243 const char *ap_proxy_host2addr(const char *host, struct hostent *reqhp);
244 int ap_proxy_cache_send(request_rec *r, ap_cache_el *c);
245 int ap_proxy_cache_should_cache(request_rec *r, apr_table_t *resp_hdrs,
247 int ap_proxy_cache_update(ap_cache_el *c);
248 void ap_proxy_cache_error(ap_cache_el **r);
249 int ap_proxyerror(request_rec *r, int statuscode, const char *message);
250 int ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
251 int ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
252 int ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
253 int ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
254 apr_status_t ap_proxy_doconnect(apr_socket_t *sock, char *host, apr_uint32_t port, request_rec *r);
255 int ap_proxy_garbage_init(server_rec *, apr_pool_t *);
256 /* This function is called by ap_table_do() for all header lines */
257 int ap_proxy_send_hdr_line(void *p, const char *key, const char *value);
258 unsigned ap_proxy_bputs2(const char *data, apr_socket_t *client, ap_cache_el *cache);
260 #endif /*MOD_PROXY_H*/