]> granicus.if.org Git - apache/blob - modules/proxy/mod_proxy.h
Initial support for proxy protocol handler sub-modules. Work continues.
[apache] / modules / proxy / mod_proxy.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 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    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
69
70    This code is once again experimental!
71
72    Things to do:
73
74    1. Make it completely work (for FTP too)
75
76    2. HTTP/1.1
77
78    Chuck Murcko <chuck@topsail.org> 02-06-01
79
80  */
81
82 #define CORE_PRIVATE
83
84 #include "apr.h"
85 #include "apr_compat.h"
86 #include "apr_lib.h"
87 #include "apr_strings.h"
88 #include "apr_buckets.h"
89 #include "apr_md5.h"
90 #include "apr_pools.h"
91 #include "apr_strings.h"
92 #include "apr_hooks.h"
93
94 #include "httpd.h"
95 #include "http_config.h"
96 #include "ap_config.h"
97 #include "http_core.h"
98 #include "http_protocol.h"
99 #include "http_request.h"
100 #include "http_vhost.h"
101 #include "http_main.h"
102 #include "http_log.h"
103 #include "http_connection.h"
104 #include "util_filter.h"
105 #include "util_date.h"
106 #include "util_uri.h"
107 #include "mod_core.h"
108
109
110 #if APR_HAVE_NETDB_H
111 #include <netdb.h>
112 #endif
113 #if APR_HAVE_SYS_SOCKET_H
114 #include <sys/socket.h>
115 #endif
116 #if APR_HAVE_NETINET_IN_H
117 #include <netinet/in.h>
118 #endif
119 #if APR_HAVE_ARPA_INET_H
120 #include <arpa/inet.h>
121 #endif
122
123 extern module AP_MODULE_DECLARE_DATA proxy_module;
124
125 /* for proxy_canonenc() */
126 enum enctype {
127     enc_path, enc_search, enc_user, enc_fpath, enc_parm
128 };
129
130 #if APR_CHARSET_EBCDIC
131 #define CRLF   "\r\n"
132 #else /*APR_CHARSET_EBCDIC*/
133 #define CRLF   "\015\012"
134 #endif /*APR_CHARSET_EBCDIC*/
135
136 /* default Max-Forwards header setting */
137 #define DEFAULT_MAX_FORWARDS    10
138
139 /* static information about a remote proxy */
140 struct proxy_remote {
141     const char *scheme;         /* the schemes handled by this proxy, or '*' */
142     const char *protocol;       /* the scheme used to talk to this proxy */
143     const char *hostname;       /* the hostname of this proxy */
144     int port;                   /* the port for this proxy */
145 };
146
147 struct proxy_alias {
148     const char *real;
149     const char *fake;
150 };
151
152 struct dirconn_entry {
153     char *name;
154     struct in_addr addr, mask;
155     struct hostent *hostentry;
156     int (*matcher) (struct dirconn_entry * This, request_rec *r);
157 };
158
159 struct noproxy_entry {
160     const char *name;
161     struct apr_sockaddr_t *addr;
162 };
163
164 typedef struct {
165     apr_array_header_t *proxies;
166     apr_array_header_t *aliases;
167     apr_array_header_t *raliases;
168     apr_array_header_t *noproxies;
169     apr_array_header_t *dirconn;
170     apr_array_header_t *allowed_connect_ports;
171     const char *domain;         /* domain name to use in absence of a domain name in the request */
172     int req;                    /* true if proxy requests are enabled */
173     char req_set;
174     enum {
175       via_off,
176       via_on,
177       via_block,
178       via_full
179     } viaopt;                   /* how to deal with proxy Via: headers */
180     char viaopt_set;
181     size_t recv_buffer_size;
182     char recv_buffer_size_set;
183     long maxfwd;
184     char maxfwd_set;
185 } proxy_server_conf;
186
187 struct per_thread_data {
188     struct hostent hpbuf;
189     u_long ipaddr;
190     char *charpbuf[2];
191 };
192
193 typedef struct {
194     conn_rec *connection;
195     char *hostname;
196     apr_port_t port;
197 } proxy_conn_rec;
198
199 typedef struct {
200         float cache_completion; /* completion percentage */
201         int content_length; /* length of the content */
202 } proxy_completion;
203
204
205 /* Function prototypes */
206
207 /* proxy_connect.c */
208
209 int ap_proxy_connect_handler(request_rec *r, char *url,
210                           const char *proxyhost, apr_port_t proxyport);
211
212 /* proxy_ftp.c */
213
214 int ap_proxy_ftp_canon(request_rec *r, char *url, const char *scheme, apr_port_t def_port);
215 int ap_proxy_ftp_handler(request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport);
216 apr_status_t ap_proxy_send_dir_filter(ap_filter_t *f,
217                                       apr_bucket_brigade *bb);
218
219
220 /* proxy_http.c */
221
222 int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme,
223                      apr_port_t def_port);
224 int ap_proxy_http_handler(request_rec *r, char *url,
225                        const char *proxyhost, apr_port_t proxyport);
226
227 /* proxy_util.c */
228
229 request_rec *make_fake_req(conn_rec *c, request_rec *r);
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, request_rec *rp, char *buffer, int size, conn_rec *c);
238 int ap_proxy_liststr(const char *list, const char *val);
239 char *ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
240 int ap_proxy_hex2sec(const char *x);
241 void ap_proxy_sec2hex(int t, char *y);
242 const char *ap_proxy_host2addr(const char *host, struct hostent *reqhp);
243 int ap_proxyerror(request_rec *r, int statuscode, const char *message);
244 int ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
245 int ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
246 int ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
247 int ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
248 int ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
249 int ap_proxy_pre_http_connection(conn_rec *c, request_rec *r);
250 apr_status_t ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
251 void ap_proxy_reset_output_filters(conn_rec *c);
252
253
254 /* hooks */
255
256
257 AP_DECLARE_HOOK(int, proxy_scheme_handler, (request_rec *r, char *url, const char *proxyhost, apr_port_t proxyport))
258 AP_DECLARE_HOOK(int, proxy_canon_handler, (request_rec *r, char *url, const char *scheme, apr_port_t def_port))
259
260
261 #endif /*MOD_PROXY_H*/