]> granicus.if.org Git - apache/blob - modules/proxy/mod_proxy.h
It never fails. I sit on a patch for awhile and
[apache] / 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  * @file  mod_proxy.h
22  * @brief Proxy Extension Module for Apache
23  *
24  * @defgroup MOD_PROXY mod_proxy
25  * @ingroup  APACHE_MODS
26  * @{
27  */
28
29 /*
30
31    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
32
33    This code is once again experimental!
34
35    Things to do:
36
37    1. Make it completely work (for FTP too)
38
39    2. HTTP/1.1
40
41    Chuck Murcko <chuck@topsail.org> 02-06-01
42
43  */
44
45 #define CORE_PRIVATE
46
47 #include "apr_hooks.h"
48 #include "apr.h"
49 #include "apr_lib.h"
50 #include "apr_strings.h"
51 #include "apr_buckets.h"
52 #include "apr_md5.h"
53 #include "apr_network_io.h"
54 #include "apr_pools.h"
55 #include "apr_strings.h"
56 #include "apr_uri.h"
57 #include "apr_date.h"
58 #include "apr_strmatch.h"
59 #include "apr_fnmatch.h"
60 #include "apr_reslist.h"
61 #define APR_WANT_STRFUNC
62 #include "apr_want.h"
63
64 #include "httpd.h"
65 #include "http_config.h"
66 #include "ap_config.h"
67 #include "http_core.h"
68 #include "http_protocol.h"
69 #include "http_request.h"
70 #include "http_vhost.h"
71 #include "http_main.h"
72 #include "http_log.h"
73 #include "http_connection.h"
74 #include "util_filter.h"
75 #include "util_ebcdic.h"
76 #include "ap_provider.h"
77
78 #if APR_HAVE_NETINET_IN_H
79 #include <netinet/in.h>
80 #endif
81 #if APR_HAVE_ARPA_INET_H
82 #include <arpa/inet.h>
83 #endif
84
85 /* for proxy_canonenc() */
86 enum enctype {
87     enc_path, enc_search, enc_user, enc_fpath, enc_parm
88 };
89
90 #if APR_CHARSET_EBCDIC
91 #define CRLF   "\r\n"
92 #else /*APR_CHARSET_EBCDIC*/
93 #define CRLF   "\015\012"
94 #endif /*APR_CHARSET_EBCDIC*/
95
96 /* default Max-Forwards header setting */
97 #define DEFAULT_MAX_FORWARDS    10
98
99 /* static information about a remote proxy */
100 struct proxy_remote {
101     const char *scheme;     /* the schemes handled by this proxy, or '*' */
102     const char *protocol;   /* the scheme used to talk to this proxy */
103     const char *hostname;   /* the hostname of this proxy */
104     apr_port_t  port;       /* the port for this proxy */
105     ap_regex_t *regexp;        /* compiled regex (if any) for the remote */
106     int use_regex;          /* simple boolean. True if we have a regex pattern */
107 };
108
109 struct proxy_alias {
110     const char  *real;
111     const char  *fake;
112 };
113
114 struct dirconn_entry {
115     char *name;
116     struct in_addr addr, mask;
117     struct apr_sockaddr_t *hostaddr;
118     int (*matcher) (struct dirconn_entry * This, request_rec *r);
119 };
120
121 struct noproxy_entry {
122     const char *name;
123     struct apr_sockaddr_t *addr;
124 };
125
126 typedef struct proxy_balancer  proxy_balancer;
127 typedef struct proxy_worker    proxy_worker;
128 typedef struct proxy_conn_pool proxy_conn_pool;
129 typedef struct proxy_balancer_method proxy_balancer_method;
130
131 typedef struct {
132     apr_array_header_t *proxies;
133     apr_array_header_t *sec_proxy;
134     apr_array_header_t *aliases;
135     apr_array_header_t *noproxies;
136     apr_array_header_t *dirconn;
137     apr_array_header_t *allowed_connect_ports;
138     apr_array_header_t *workers;
139     apr_array_header_t *balancers;
140     proxy_worker       *forward;    /* forward proxy worker */
141     proxy_worker       *reverse;    /* reverse "module-driven" proxy worker */
142     const char *domain;     /* domain name to use in absence of a domain name in the request */
143     int req;                /* true if proxy requests are enabled */
144     char req_set;
145     enum {
146       via_off,
147       via_on,
148       via_block,
149       via_full
150     } viaopt;                   /* how to deal with proxy Via: headers */
151     char viaopt_set;
152     apr_size_t recv_buffer_size;
153     char recv_buffer_size_set;
154     apr_size_t io_buffer_size;
155     char io_buffer_size_set;
156     long maxfwd;
157     char maxfwd_set;
158     /** 
159      * the following setting masks the error page
160      * returned from the 'proxied server' and just 
161      * forwards the status code upwards.
162      * This allows the main server (us) to generate
163      * the error page, (so it will look like a error
164      * returned from the rest of the system 
165      */
166     int error_override;
167     int error_override_set;
168     int preserve_host;
169     int preserve_host_set;
170     apr_interval_time_t timeout;
171     char timeout_set;
172     enum {
173       bad_error,
174       bad_ignore,
175       bad_body
176     } badopt;                   /* how to deal with bad headers */
177     char badopt_set;
178 /* putting new stuff on the end maximises binary back-compatibility.
179  * the strmatch_patterns are really a const just to have a
180  * case-independent strstr.
181  */
182     enum {
183         status_off,
184         status_on,
185         status_full
186     } proxy_status;             /* Status display options */
187     char proxy_status_set;
188     apr_pool_t *pool;           /* Pool used for allocating this struct */
189 } proxy_server_conf;
190
191
192 typedef struct {
193     const char *p;            /* The path */
194     int         p_is_fnmatch; /* Is this path an fnmatch candidate? */
195     ap_regex_t  *r;            /* Is this a regex? */
196
197 /* ProxyPassReverse and friends are documented as working inside
198  * <Location>.  But in fact they never have done in the case of
199  * more than one <Location>, because the server_conf can't see it.
200  * We need to move them to the per-dir config.
201  * Discussed in February:
202  * http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=110726027118798&w=2
203  */
204     apr_array_header_t *raliases;
205     apr_array_header_t* cookie_paths;
206     apr_array_header_t* cookie_domains;
207     const apr_strmatch_pattern* cookie_path_str;
208     const apr_strmatch_pattern* cookie_domain_str;
209 } proxy_dir_conf;
210
211 typedef struct {
212     conn_rec     *connection;
213     const char   *hostname;
214     apr_port_t   port;
215     int          is_ssl;
216     apr_pool_t   *pool;     /* Subpool used for creating socket */
217     apr_socket_t *sock;     /* Connection socket */
218     apr_sockaddr_t *addr;   /* Preparsed remote address info */
219     apr_uint32_t flags;     /* Conection flags */
220     int          close;     /* Close 'this' connection */
221     int          close_on_recycle; /* Close the connection when returning to pool */
222     proxy_worker *worker;   /* Connection pool this connection belogns to */
223     void         *data;     /* per scheme connection data */
224 #if APR_HAS_THREADS
225     int          inreslist; /* connection in apr_reslist? */
226 #endif
227 } proxy_conn_rec;
228
229 typedef struct {
230         float cache_completion; /* completion percentage */
231         int content_length; /* length of the content */
232 } proxy_completion;
233
234 /* Connection pool */
235 struct proxy_conn_pool {
236     apr_pool_t     *pool;   /* The pool used in constructor and destructor calls */
237     apr_sockaddr_t *addr;   /* Preparsed remote address info */
238 #if APR_HAS_THREADS
239     apr_reslist_t  *res;    /* Connection resource list */
240 #endif
241     proxy_conn_rec *conn;   /* Single connection for prefork mpm's */
242 };
243
244 /* worker status flags */
245 #define PROXY_WORKER_INITIALIZED    0x0001
246 #define PROXY_WORKER_IGNORE_ERRORS  0x0002
247 #define PROXY_WORKER_IN_SHUTDOWN    0x0010
248 #define PROXY_WORKER_DISABLED       0x0020
249 #define PROXY_WORKER_STOPPED        0x0040
250 #define PROXY_WORKER_IN_ERROR       0x0080
251 #define PROXY_WORKER_HOT_STANDBY    0x0100
252
253 #define PROXY_WORKER_NOT_USABLE_BITMAP ( PROXY_WORKER_IN_SHUTDOWN | \
254 PROXY_WORKER_DISABLED | PROXY_WORKER_STOPPED | PROXY_WORKER_IN_ERROR )
255
256 #define PROXY_WORKER_IS_INITIALIZED(f)   ( (f)->s->status & \
257   PROXY_WORKER_INITIALIZED )
258
259 #define PROXY_WORKER_IS_STANDBY(f)   ( (f)->s->status & \
260   PROXY_WORKER_HOT_STANDBY )
261
262 #define PROXY_WORKER_IS_USABLE(f)   ( !((f)->s->status & \
263   (PROXY_WORKER_NOT_USABLE_BITMAP)) && PROXY_WORKER_IS_INITIALIZED(f) )
264
265 /* default worker retry timeout in seconds */
266 #define PROXY_WORKER_DEFAULT_RETRY  60
267 #define PROXY_WORKER_MAX_ROUTE_SIZ  63
268
269 /* Runtime worker status informations. Shared in scoreboard */
270 typedef struct {
271     int             status;
272     apr_time_t      error_time; /* time of the last error */
273     int             retries;    /* number of retries on this worker */
274     int             lbstatus;   /* Current lbstatus */
275     int             lbfactor;   /* dynamic lbfactor */
276     apr_off_t       transferred;/* Number of bytes transferred to remote */
277     apr_off_t       read;       /* Number of bytes read from remote */
278     apr_size_t      elected;    /* Number of times the worker was elected */
279     char            route[PROXY_WORKER_MAX_ROUTE_SIZ+1];
280     char            redirect[PROXY_WORKER_MAX_ROUTE_SIZ+1];
281     void            *context;   /* general purpose storage */
282 } proxy_worker_stat;
283
284 /* Worker configuration */
285 struct proxy_worker {
286     int             id;         /* scoreboard id */
287     apr_interval_time_t retry;  /* retry interval */
288     int             lbfactor;   /* initial load balancing factor */
289     const char      *name;
290     const char      *scheme;    /* scheme to use ajp|http|https */
291     const char      *hostname;  /* remote backend address */
292     const char      *route;     /* balancing route */
293     const char      *redirect;  /* temporary balancing redirection route */
294     int             status;     /* temporary worker status */
295     apr_port_t      port;
296     int             min;        /* Desired minimum number of available connections */
297     int             smax;       /* Soft maximum on the total number of connections */
298     int             hmax;       /* Hard maximum on the total number of connections */
299     apr_interval_time_t ttl;    /* maximum amount of time in seconds a connection
300                                  * may be available while exceeding the soft limit */
301     apr_interval_time_t timeout; /* connection timeout */
302     char                timeout_set;
303     apr_interval_time_t acquire; /* acquire timeout when the maximum number of connections is exceeded */
304     char                acquire_set;
305     apr_size_t          recv_buffer_size;
306     char                recv_buffer_size_set;
307     apr_size_t          io_buffer_size;
308     char                io_buffer_size_set;
309     char                keepalive;
310     char                keepalive_set;
311     proxy_conn_pool     *cp;        /* Connection pool to use */
312     proxy_worker_stat   *s;         /* Shared data */
313     void                *opaque;    /* per scheme worker data */
314     int                 is_address_reusable;
315 #if APR_HAS_THREADS
316     apr_thread_mutex_t  *mutex;  /* Thread lock for updating address cache */
317 #endif
318     void                *context;   /* general purpose storage */
319     enum {
320          flush_off,
321          flush_on,
322          flush_auto
323     } flush_packets;           /* control AJP flushing */
324     int                 flush_wait;  /* poll wait time in microseconds if flush_auto */
325 };
326
327 /*
328  * Wait 10000 microseconds to find out if more data is currently
329  * available at the backend. Just an arbitrary choose.
330  */
331 #define PROXY_FLUSH_WAIT 10000
332
333 struct proxy_balancer {
334     apr_array_header_t *workers; /* array of proxy_workers */
335     const char *name;            /* name of the load balancer */
336     const char *sticky;          /* sticky session identifier */
337     int         sticky_force;    /* Disable failover for sticky sessions */
338     apr_interval_time_t timeout; /* Timeout for waiting on free connection */
339     int                 max_attempts; /* Number of attempts before failing */
340     char                max_attempts_set;
341     proxy_balancer_method *lbmethod;
342
343     /* XXX: Perhaps we will need the proc mutex too.
344      * Altrough we are only using arithmetic operations
345      * it may lead to a incorrect calculations.
346      * For now use only the thread mutex.
347      */
348 #if APR_HAS_THREADS
349     apr_thread_mutex_t  *mutex;  /* Thread lock for updating lb params */
350 #endif
351     void            *context;   /* general purpose storage */
352 };
353
354 struct proxy_balancer_method {
355     const char *name;            /* name of the load balancer method*/
356     proxy_worker *(*finder)(proxy_balancer *balancer,
357                             request_rec *r);
358     void            *context;   /* general purpose storage */
359 };
360
361 #if APR_HAS_THREADS
362 #define PROXY_THREAD_LOCK(x)      apr_thread_mutex_lock((x)->mutex)
363 #define PROXY_THREAD_UNLOCK(x)    apr_thread_mutex_unlock((x)->mutex)
364 #else
365 #define PROXY_THREAD_LOCK(x)      APR_SUCCESS
366 #define PROXY_THREAD_UNLOCK(x)    APR_SUCCESS
367 #endif
368
369 /* hooks */
370
371 /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
372  * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
373  */
374 #if !defined(WIN32)
375 #define PROXY_DECLARE(type)            type
376 #define PROXY_DECLARE_NONSTD(type)     type
377 #define PROXY_DECLARE_DATA
378 #elif defined(PROXY_DECLARE_STATIC)
379 #define PROXY_DECLARE(type)            type __stdcall
380 #define PROXY_DECLARE_NONSTD(type)     type
381 #define PROXY_DECLARE_DATA
382 #elif defined(PROXY_DECLARE_EXPORT)
383 #define PROXY_DECLARE(type)            __declspec(dllexport) type __stdcall
384 #define PROXY_DECLARE_NONSTD(type)     __declspec(dllexport) type
385 #define PROXY_DECLARE_DATA             __declspec(dllexport)
386 #else
387 #define PROXY_DECLARE(type)            __declspec(dllimport) type __stdcall
388 #define PROXY_DECLARE_NONSTD(type)     __declspec(dllimport) type
389 #define PROXY_DECLARE_DATA             __declspec(dllimport)
390 #endif
391
392 /**
393  * Hook an optional proxy hook.  Unlike static hooks, this uses a macro
394  * instead of a function.
395  */
396 #define PROXY_OPTIONAL_HOOK(name,fn,pre,succ,order) \
397         APR_OPTIONAL_HOOK(proxy,name,fn,pre,succ,order)
398
399 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, 
400                           proxy_worker *worker, proxy_server_conf *conf, char *url, 
401                           const char *proxyhost, apr_port_t proxyport))
402 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, 
403                           char *url))
404
405 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
406 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) 
407
408 /**
409  * pre request hook.
410  * It will return the most suitable worker at the moment
411  * and coresponding balancer.
412  * The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
413  * and then the scheme_handler is called.
414  *
415  */
416 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
417                           proxy_balancer **balancer,
418                           request_rec *r,
419                           proxy_server_conf *conf, char **url))                          
420 /**
421  * post request hook.
422  * It is called after request for updating runtime balancer status.
423  */
424 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
425                           proxy_balancer *balancer, request_rec *r,
426                           proxy_server_conf *conf))
427
428 /**
429  * request status hook
430  * It is called after all proxy processing has been done.  This gives other
431  * modules a chance to create default content on failure, for example
432  */
433 APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status,
434                           (int *status, request_rec *r))
435
436 /* proxy_util.c */
437
438 PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
439 PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
440 PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
441 PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
442                                        int forcedec, int proxyreq);
443 PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
444                                            char **passwordp, char **hostp, apr_port_t *port);
445 PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
446 PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
447 PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
448 PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
449 PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
450 PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
451 PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
452 PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
453 PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
454 PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
455 PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
456 PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
457 PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
458 PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
459 /* DEPRECATED (will be replaced with ap_proxy_connect_backend */
460 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 *);
461 PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
462 PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
463 PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c);
464 PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, conn_rec *c, request_rec *r, const char *var);
465
466 /* Header mapping functions, and a typedef of their signature */
467 PROXY_DECLARE(const char *) ap_proxy_location_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *url);
468 PROXY_DECLARE(const char *) ap_proxy_cookie_reverse_map(request_rec *r, proxy_dir_conf *conf, const char *str);
469
470 #if !defined(WIN32)
471 typedef const char *(*ap_proxy_header_reverse_map_fn)(request_rec *,
472                        proxy_dir_conf *, const char *);
473 #elif defined(PROXY_DECLARE_STATIC)
474 typedef const char *(__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
475                                  proxy_dir_conf *, const char *);
476 #elif defined(PROXY_DECLARE_EXPORT)
477 typedef __declspec(dllexport) const char *
478   (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
479                proxy_dir_conf *, const char *);
480 #else
481 typedef __declspec(dllimport) const char *
482   (__stdcall *ap_proxy_header_reverse_map_fn)(request_rec *,
483                proxy_dir_conf *, const char *);
484 #endif
485
486
487 /* Connection pool API */
488 /**
489  * Get the worker from proxy configuration
490  * @param p     memory pool used for finding worker
491  * @param conf  current proxy server configuration
492  * @param url   url to find the worker from
493  * @return      proxy_worker or NULL if not found
494  */
495 PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
496                                                   proxy_server_conf *conf,
497                                                   const char *url);
498 /**
499  * Add the worker to proxy configuration
500  * @param worker the new worker
501  * @param p      memory pool to allocate worker from 
502  * @param conf   current proxy server configuration
503  * @param url    url containing worker name
504  * @return       error message or NULL if successfull
505  */
506 PROXY_DECLARE(const char *) ap_proxy_add_worker(proxy_worker **worker,
507                                                 apr_pool_t *p,
508                                                 proxy_server_conf *conf,
509                                                 const char *url);
510
511 /**
512  * Create new worker
513  * @param p      memory pool to allocate worker from 
514  * @return       new worker
515  */
516 PROXY_DECLARE(proxy_worker *) ap_proxy_create_worker(apr_pool_t *p);
517
518 /**
519  * Initize the worker's shared data
520  * @param conf   current proxy server configuration
521  * @param worker worker to initialize
522  * @param s      current server record
523  * @param worker worker to initialize
524  */
525 PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf,
526                                                      proxy_worker *worker,
527                                                      server_rec *s);
528
529
530 /**
531  * Initize the worker
532  * @param worker worker to initialize
533  * @param s      current server record
534  * @return       APR_SUCCESS or error code
535  */
536 PROXY_DECLARE(apr_status_t) ap_proxy_initialize_worker(proxy_worker *worker,
537                                                        server_rec *s);
538 /**
539  * Get the balancer from proxy configuration
540  * @param p     memory pool used for finding balancer
541  * @param conf  current proxy server configuration
542  * @param url   url to find the worker from. Has to have balancer:// prefix
543  * @return      proxy_balancer or NULL if not found
544  */
545 PROXY_DECLARE(proxy_balancer *) ap_proxy_get_balancer(apr_pool_t *p,
546                                                       proxy_server_conf *conf,
547                                                       const char *url);
548 /**
549  * Add the balancer to proxy configuration
550  * @param balancer the new balancer
551  * @param p      memory pool to allocate balancer from 
552  * @param conf   current proxy server configuration
553  * @param url    url containing balancer name
554  * @return       error message or NULL if successfull
555  */
556 PROXY_DECLARE(const char *) ap_proxy_add_balancer(proxy_balancer **balancer,
557                                                   apr_pool_t *p,
558                                                   proxy_server_conf *conf,
559                                                   const char *url);
560
561 /**
562  * Add the worker to the balancer
563  * @param pool     memory pool for adding worker 
564  * @param balancer balancer to add to
565  * @param balancer worker to add
566  * @note Single worker can be added to multiple balancers.
567  */
568 PROXY_DECLARE(void) ap_proxy_add_worker_to_balancer(apr_pool_t *pool,
569                                                     proxy_balancer *balancer,
570                                                     proxy_worker *worker);
571 /**
572  * Get the most suitable worker and(or) balancer for the request
573  * @param worker   worker used for processing request
574  * @param balancer balancer used for processing request
575  * @param r        current request
576  * @param conf     current proxy server configuration
577  * @param url      request url that balancer can rewrite.
578  * @return         OK or  HTTP_XXX error 
579  * @note It calls balancer pre_request hook if the url starts with balancer://
580  * The balancer then rewrites the url to particular worker, like http://host:port
581  */
582 PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
583                                         proxy_balancer **balancer,
584                                         request_rec *r,
585                                         proxy_server_conf *conf,
586                                         char **url);
587 /**
588  * Post request worker and balancer cleanup
589  * @param worker   worker used for processing request
590  * @param balancer balancer used for processing request
591  * @param r        current request
592  * @param conf     current proxy server configuration
593  * @return         OK or  HTTP_XXX error
594  * @note When ever the pre_request is called, the post_request has to be
595  * called too. 
596  */
597 PROXY_DECLARE(int) ap_proxy_post_request(proxy_worker *worker,
598                                          proxy_balancer *balancer,
599                                          request_rec *r,
600                                          proxy_server_conf *conf);
601
602 /**
603  * Request status function
604  * @param status   status of proxy request
605  * @return         OK or DECLINED
606  */
607  PROXY_DECLARE(int) ap_proxy_request_status(int *status, request_rec *r);
608
609 /**
610  * Deternime backend hostname and port
611  * @param p       memory pool used for processing
612  * @param r       current request
613  * @param conf    current proxy server configuration
614  * @param worker  worker used for processing request
615  * @param conn    proxy connection struct
616  * @param uri     processed uri
617  * @param url     request url
618  * @param proxyname are we connecting directly or via s proxy
619  * @param proxyport proxy host port
620  * @param server_portstr Via headers server port
621  * @param server_portstr_size size of the server_portstr buffer
622  * @return         OK or HTTP_XXX error
623  */                                         
624 PROXY_DECLARE(int) ap_proxy_determine_connection(apr_pool_t *p, request_rec *r,
625                                                  proxy_server_conf *conf,
626                                                  proxy_worker *worker,
627                                                  proxy_conn_rec *conn,
628                                                  apr_uri_t *uri,
629                                                  char **url,
630                                                  const char *proxyname,
631                                                  apr_port_t proxyport,
632                                                  char *server_portstr,
633                                                  int server_portstr_size);
634 /**
635  * Mark a worker for retry
636  * @param proxy_function calling proxy scheme (http, ajp, ...)
637  * @param conf    current proxy server configuration
638  * @param worker  worker used for retrying
639  * @param s       current server record
640  * @return        OK if marked for retry, DECLINED otherwise
641  * @note Worker will be marker for retry if the time of the last retry
642  * has been ellapsed. In case there is no retry option set, defaults to
643  * number_of_retries seconds.
644  */                                         
645 PROXY_DECLARE(int) ap_proxy_retry_worker(const char *proxy_function,
646                                          proxy_worker *worker,
647                                          server_rec *s);
648 /**
649  * Acquire a connection from workers connection pool
650  * @param proxy_function calling proxy scheme (http, ajp, ...)
651  * @param conn    acquired connection
652  * @param worker  worker used for obtaining connection
653  * @param s       current server record
654  * @return        OK or HTTP_XXX error
655  * @note If the number of connections is exhaused the function will
656  * block untill the timeout is reached.
657  */                                         
658 PROXY_DECLARE(int) ap_proxy_acquire_connection(const char *proxy_function,
659                                                proxy_conn_rec **conn,
660                                                proxy_worker *worker,
661                                                server_rec *s);
662 /**
663  * Release a connection back to worker connection pool
664  * @param proxy_function calling proxy scheme (http, ajp, ...)
665  * @param conn    acquired connection
666  * @param s       current server record
667  * @return        OK or HTTP_XXX error
668  * @note The connection will be closed if conn->close_on_release is set
669  */                                         
670 PROXY_DECLARE(int) ap_proxy_release_connection(const char *proxy_function,
671                                                proxy_conn_rec *conn,
672                                                server_rec *s);
673 /**
674  * Make a connection to the backend
675  * @param proxy_function calling proxy scheme (http, ajp, ...)
676  * @param conn    acquired connection
677  * @param worker  connection worker
678  * @param s       current server record
679  * @return        OK or HTTP_XXX error
680  * @note In case the socket already exists for conn, just check the link
681  * status.
682  */                                         
683 PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
684                                             proxy_conn_rec *conn,
685                                             proxy_worker *worker,
686                                             server_rec *s);
687 /**
688  * Make a connection record for backend connection
689  * @param proxy_function calling proxy scheme (http, ajp, ...)
690  * @param conn    acquired connection
691  * @param c       client connection record
692  * @param s       current server record
693  * @return        OK or HTTP_XXX error
694  */                                         
695 PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
696                                               proxy_conn_rec *conn,
697                                               conn_rec *c, server_rec *s);
698 /**
699  * Signal the upstream chain that the connection to the backend broke in the
700  * middle of the response. This is done by sending an error bucket with
701  * status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
702  * @param r       current request record of client request
703  * @param brigade The brigade that is sent through the output filter chain
704  */
705 PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r,
706                                            apr_bucket_brigade *brigade);
707
708 /* Scoreboard */
709 #if MODULE_MAGIC_NUMBER_MAJOR > 20020903
710 #define PROXY_HAS_SCOREBOARD 1
711 #else
712 #define PROXY_HAS_SCOREBOARD 0
713 #endif
714
715 #define PROXY_LBMETHOD "proxylbmethod"
716
717 /* The number of dynamic workers that can be added when reconfiguring.
718  * If this limit is reached you must stop and restart the server.
719  */
720 #define PROXY_DYNAMIC_BALANCER_LIMIT    16
721 /**
722  * Calculate number of maximum number of workers in scoreboard.
723  * @return  number of workers to allocate in the scoreboard
724  */
725 int ap_proxy_lb_workers(void);
726
727 /* For proxy_util */
728 extern module PROXY_DECLARE_DATA proxy_module;
729
730 extern int PROXY_DECLARE_DATA proxy_lb_workers;
731
732 #endif /*MOD_PROXY_H*/
733 /** @} */