upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / proxy / mod_proxy.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef MOD_PROXY_H
18 #define MOD_PROXY_H 
19
20 /*
21  * Main include file for the Apache proxy
22  */
23
24 /*
25
26    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
27
28    This code is once again experimental!
29
30    Things to do:
31
32    1. Make it completely work (for FTP too)
33
34    2. HTTP/1.1
35
36    Chuck Murcko <chuck@topsail.org> 02-06-01
37
38  */
39
40 #define CORE_PRIVATE
41
42 #include "apr_hooks.h"
43 #include "apr.h"
44 #include "apr_lib.h"
45 #include "apr_strings.h"
46 #include "apr_buckets.h"
47 #include "apr_md5.h"
48 #include "apr_network_io.h"
49 #include "apr_pools.h"
50 #include "apr_strings.h"
51 #include "apr_uri.h"
52 #include "apr_date.h"
53 #include "apr_fnmatch.h"
54 #define APR_WANT_STRFUNC
55 #include "apr_want.h"
56
57 #include "httpd.h"
58 #include "http_config.h"
59 #include "ap_config.h"
60 #include "http_core.h"
61 #include "http_protocol.h"
62 #include "http_request.h"
63 #include "http_vhost.h"
64 #include "http_main.h"
65 #include "http_log.h"
66 #include "http_connection.h"
67 #include "util_filter.h"
68 #include "util_ebcdic.h"
69
70 #if APR_HAVE_NETINET_IN_H
71 #include <netinet/in.h>
72 #endif
73 #if APR_HAVE_ARPA_INET_H
74 #include <arpa/inet.h>
75 #endif
76
77 /* for proxy_canonenc() */
78 enum enctype {
79     enc_path, enc_search, enc_user, enc_fpath, enc_parm
80 };
81
82 #if APR_CHARSET_EBCDIC
83 #define CRLF   "\r\n"
84 #else /*APR_CHARSET_EBCDIC*/
85 #define CRLF   "\015\012"
86 #endif /*APR_CHARSET_EBCDIC*/
87
88 /* default Max-Forwards header setting */
89 #define DEFAULT_MAX_FORWARDS    10
90
91 /* static information about a remote proxy */
92 struct proxy_remote {
93     const char *scheme;         /* the schemes handled by this proxy, or '*' */
94     const char *protocol;       /* the scheme used to talk to this proxy */
95     const char *hostname;       /* the hostname of this proxy */
96     apr_port_t  port;           /* the port for this proxy */
97     regex_t *regexp;            /* compiled regex (if any) for the remote */
98     int use_regex;              /* simple boolean. True if we have a regex pattern */
99 };
100
101 struct proxy_alias {
102     const char *real;
103     const char *fake;
104 };
105
106 struct dirconn_entry {
107     char *name;
108     struct in_addr addr, mask;
109     struct apr_sockaddr_t *hostaddr;
110     int (*matcher) (struct dirconn_entry * This, request_rec *r);
111 };
112
113 struct noproxy_entry {
114     const char *name;
115     struct apr_sockaddr_t *addr;
116 };
117
118 typedef struct {
119     apr_array_header_t *proxies;
120     apr_array_header_t *sec_proxy;
121     apr_array_header_t *aliases;
122     apr_array_header_t *raliases;
123     apr_array_header_t *noproxies;
124     apr_array_header_t *dirconn;
125     apr_array_header_t *allowed_connect_ports;
126     const char *domain;         /* domain name to use in absence of a domain name in the request */
127     int req;                    /* true if proxy requests are enabled */
128     char req_set;
129     enum {
130       via_off,
131       via_on,
132       via_block,
133       via_full
134     } viaopt;                   /* how to deal with proxy Via: headers */
135     char viaopt_set;
136     apr_size_t recv_buffer_size;
137     char recv_buffer_size_set;
138     apr_size_t io_buffer_size;
139     char io_buffer_size_set;
140     long maxfwd;
141     char maxfwd_set;
142     /** 
143      * the following setting masks the error page
144      * returned from the 'proxied server' and just 
145      * forwards the status code upwards.
146      * This allows the main server (us) to generate
147      * the error page, (so it will look like a error
148      * returned from the rest of the system 
149      */
150     int error_override;
151     int error_override_set;
152     int preserve_host;
153     int preserve_host_set;
154     apr_interval_time_t timeout;
155     apr_interval_time_t timeout_set;
156     enum {
157       bad_error,
158       bad_ignore,
159       bad_body
160     } badopt;                   /* how to deal with bad headers */
161     char badopt_set;
162
163 } proxy_server_conf;
164
165 typedef struct {
166     const char *p;            /* The path */
167     int         p_is_fnmatch; /* Is this path an fnmatch candidate? */
168     regex_t    *r;            /* Is this a regex? */
169     const char *ftp_directory_charset;
170 } proxy_dir_conf;
171
172 typedef struct {
173     conn_rec *connection;
174     char *hostname;
175     apr_port_t port;
176     int is_ssl;
177 } proxy_conn_rec;
178
179 typedef struct {
180         float cache_completion; /* completion percentage */
181         int content_length; /* length of the content */
182 } proxy_completion;
183
184
185 /* hooks */
186
187 /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
188  * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
189  */
190 #if !defined(WIN32)
191 #define PROXY_DECLARE(type)            type
192 #define PROXY_DECLARE_NONSTD(type)     type
193 #define PROXY_DECLARE_DATA
194 #elif defined(PROXY_DECLARE_STATIC)
195 #define PROXY_DECLARE(type)            type __stdcall
196 #define PROXY_DECLARE_NONSTD(type)     type
197 #define PROXY_DECLARE_DATA
198 #elif defined(PROXY_DECLARE_EXPORT)
199 #define PROXY_DECLARE(type)            __declspec(dllexport) type __stdcall
200 #define PROXY_DECLARE_NONSTD(type)     __declspec(dllexport) type
201 #define PROXY_DECLARE_DATA             __declspec(dllexport)
202 #else
203 #define PROXY_DECLARE(type)            __declspec(dllimport) type __stdcall
204 #define PROXY_DECLARE_NONSTD(type)     __declspec(dllimport) type
205 #define PROXY_DECLARE_DATA             __declspec(dllimport)
206 #endif
207
208 /**
209  * Hook an optional proxy hook.  Unlike static hooks, this uses a macro
210  * instead of a function.
211  */
212 #define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
213         APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
214
215 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, 
216                           proxy_server_conf *conf, char *url, 
217                           const char *proxyhost, apr_port_t proxyport))
218 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, 
219                           char *url))
220
221 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
222 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) 
223
224 /* proxy_util.c */
225
226 PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
227 PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
228 PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
229 PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
230                         int isenc);
231 PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
232                          char **passwordp, char **hostp, apr_port_t *port);
233 PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
234 PROXY_DECLARE(apr_table_t *)ap_proxy_read_headers(request_rec *r, request_rec *rp, char *buffer, int size, conn_rec *c);
235 PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
236 PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
237 PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
238 PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
239 PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
240 PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
241 PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
242 PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
243 PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
244 PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
245 PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
246 PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
247 PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
248 PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, server_rec *, apr_pool_t *);
249 PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
250 PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
251
252 /* For proxy_util */
253 extern module AP_MODULE_DECLARE_DATA proxy_module;
254
255 #endif /*MOD_PROXY_H*/