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