]> granicus.if.org Git - apache/blob - modules/proxy/mod_proxy.h
*) continued header revamping
[apache] / modules / proxy / mod_proxy.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
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
17  *    distribution.
18  *
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.
25  *
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.
30  *
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.
34  *
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
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
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/>.
53  *
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.
57  */
58
59 #ifndef MOD_PROXY_H
60 #define MOD_PROXY_H 
61
62 /*
63  * Main include file for the Apache proxy
64  */
65
66 /*
67
68    Note that the Explain() stuff is not yet complete.
69    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
70
71    If TESTING is set, then garbage collection doesn't delete ... probably a good
72    idea when hacking.
73
74    This code is once again experimental!
75
76    Things to do:
77
78    1. Make it completely work (for FTP too)
79
80    2. HTTP/1.1
81
82    3. Cache issues
83
84    Chuck Murcko <chuck@topsail.org> 02-06-01
85
86  */
87
88 #define TESTING 0
89 #undef EXPLAIN
90
91 #include "apr_compat.h"
92 #include "apr_strings.h"
93
94 #if APR_HAVE_NETDB_H
95 #include <netdb.h>
96 #endif
97 #if APR_HAVE_SYS_SOCKET_H
98 #include <sys/socket.h>
99 #endif
100 #if APR_HAVE_NETINET_IN_H
101 #include <netinet/in.h>
102 #endif
103 #if APR_HAVE_ARPA_INET_H
104 #include <arpa/inet.h>
105 #endif
106
107 #include "httpd.h"
108 #include "http_config.h"
109 #include "http_protocol.h"
110 #include "proxy_cache.h"
111
112
113 extern module AP_MODULE_DECLARE_DATA proxy_module;
114
115
116 /* for proxy_canonenc() */
117 enum enctype {
118     enc_path, enc_search, enc_user, enc_fpath, enc_parm
119 };
120
121 #define HDR_APP (0)             /* append header, for proxy_add_header() */
122 #define HDR_REP (1)             /* replace header, for proxy_add_header() */
123
124 #if APR_CHARSET_EBCDIC
125 #define CRLF   "\r\n"
126 #else /*APR_CHARSET_EBCDIC*/
127 #define CRLF   "\015\012"
128 #endif /*APR_CHARSET_EBCDIC*/
129
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 */
138
139 #define DEFAULT_CACHE_COMPLETION (0.9)
140 /* Some WWW schemes and their default ports; this is basically /etc/services */
141 struct proxy_services {
142     const char *scheme;
143     int port;
144 };
145
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 */
152 };
153
154 struct proxy_alias {
155     const char *real;
156     const char *fake;
157 };
158
159 struct dirconn_entry {
160     char *name;
161     struct in_addr addr, mask;
162     struct hostent *hostentry;
163     int (*matcher) (struct dirconn_entry * This, request_rec *r);
164 };
165
166 struct noproxy_entry {
167     const char *name;
168     struct in_addr addr;
169 };
170
171 struct nocache_entry {
172     const char *name;
173     struct in_addr addr;
174 };
175
176 typedef struct {
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 */
187     enum {
188       via_off,
189       via_on,
190       via_block,
191       via_full
192     } viaopt;                   /* how to deal with proxy Via: headers */
193     size_t recv_buffer_size;
194     ap_cache_handle_t *cache;
195 } proxy_server_conf;
196
197 struct per_thread_data {
198     struct hostent hpbuf;
199     u_long ipaddr;
200     char *charpbuf[2];
201 };
202
203 typedef struct {
204         float cache_completion; /* completion percentage */
205         int content_length; /* length of the content */
206 } proxy_completion;
207
208
209 /* Function prototypes */
210
211 /* proxy_connect.c */
212
213 int ap_proxy_connect_handler(request_rec *r, char *url,
214                           const char *proxyhost, int proxyport);
215
216 /* proxy_ftp.c */
217
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);
220
221 /* proxy_http.c */
222
223 int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
224                      int def_port);
225 int ap_proxy_http_handler(request_rec *r, char *url,
226                        const char *proxyhost, int proxyport);
227
228 /* proxy_util.c */
229
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,
233                         int isenc);
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,
246                                 const int is_HTTP1);
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);
259
260 #endif /*MOD_PROXY_H*/