]> granicus.if.org Git - apache/blob - modules/proxy/mod_proxy.c
Display worker status under server-status
[apache] / modules / proxy / mod_proxy.c
1 #define FIX_15207
2 /* Copyright 1999-2004 The Apache Software Foundation
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 #define CORE_PRIVATE
18
19 #include "mod_proxy.h"
20 #include "mod_core.h"
21 #include "apr_optional.h"
22 #include "scoreboard.h"
23 #include "mod_status.h"
24
25 #if (MODULE_MAGIC_NUMBER_MAJOR > 20020903)
26 #include "mod_ssl.h"
27 #else
28 APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
29 APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
30 #endif
31
32 #ifndef MAX
33 #define MAX(x,y) ((x) >= (y) ? (x) : (y))
34 #endif
35
36 /*
37  * A Web proxy module. Stages:
38  *
39  *  translate_name: set filename to proxy:<URL>
40  *  map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
41  *                  can't trust directory_walk/file_walk since these are
42  *                  not in our filesystem.  Prevents mod_http from serving
43  *                  the TRACE request we will set aside to handle later.
44  *  type_checker:   set type to PROXY_MAGIC_TYPE if filename begins proxy:
45  *  fix_ups:        convert the URL stored in the filename to the
46  *                  canonical form.
47  *  handler:        handle proxy requests
48  */
49
50 /* -------------------------------------------------------------- */
51 /* Translate the URL into a 'filename' */
52
53 #ifdef FIX_15207
54 /* XXX: EBCDIC safe? --nd */
55 #define x2c(x) (((x >= '0') && (x <= '9'))         \
56                    ? (x - '0')                     \
57                    : (((x >= 'a') && (x <= 'f'))   \
58                        ? (10 + x - 'a')            \
59                        : ((x >= 'A') && (x <='F')) \
60                            ? (10 + x - 'A')        \
61                            : 0                     \
62                      )                             \
63                )
64
65 static unsigned char hex2c(const char* p) {
66   const char c1 = p[1];
67   const char c2 = p[1] ? p[2]: '\0';
68   int i1 = c1 ? x2c(c1) : 0;
69   int i2 = c2 ? x2c(c2) : 0;
70   unsigned char ret = (i1 << 4) | i2;
71
72   return ret;
73 }
74 #endif
75
76 #define PROXY_COPY_CONF_PARAMS(w, c) \
77     do {                             \
78         (w)->timeout              = (c)->timeout;               \
79         (w)->timeout_set          = (c)->timeout_set;           \
80         (w)->recv_buffer_size     = (c)->recv_buffer_size;      \
81         (w)->recv_buffer_size_set = (c)->recv_buffer_size_set;  \
82         (w)->io_buffer_size       = (c)->io_buffer_size;        \
83         (w)->io_buffer_size_set   = (c)->io_buffer_size_set;    \
84     } while (0)
85
86 static const char *set_worker_param(apr_pool_t *p,
87                                     proxy_worker *worker,
88                                     const char *key,
89                                     const char *val)
90 {
91
92     int ival;
93     if (!strcasecmp(key, "loadfactor")) {
94         /* Worker load factor. Used with BalancerMamber
95          * It is a number between 1 and 100 in percents.
96          */
97         worker->lbfactor = atoi(val);
98         if (worker->lbfactor < 1 || worker->lbfactor > 100)
99             return "LoadFactor must be number between 1..100";
100     }
101     else if (!strcasecmp(key, "retry")) {
102         /* If set it will give the retry timeout for the worker
103          * The default value is 60 seconds, meaning that if
104          * in error state, it will be retried after that timeout.
105          */
106         ival = atoi(val);
107         if (ival < 1)
108             return "Retry must be at least one second";
109         worker->retry = apr_time_from_sec(ival);
110     }
111     else if (!strcasecmp(key, "ttl")) {
112         /* Time in seconds that will destroy all the connections
113          * that exced the smax 
114          */
115         ival = atoi(val);
116         if (ival < 1)
117             return "TTL must be at least one second";
118         worker->ttl = apr_time_from_sec(ival);
119     }
120     else if (!strcasecmp(key, "min")) {
121         /* Initial number of connections to remote
122          */
123         ival = atoi(val);
124         if (ival < 0)
125             return "Min must be a positive number";
126         worker->min = ival;
127     }
128     else if (!strcasecmp(key, "max")) {
129         /* Maximum number of connections to remote
130          */
131         ival = atoi(val);
132         if (ival < 0)
133             return "Max must be a positive number";
134         worker->hmax = ival;
135     }
136     /* XXX: More inteligent naming needed */
137     else if (!strcasecmp(key, "smax")) {
138         /* Maximum number of connections to remote that
139          * will not be destroyed
140          */
141         ival = atoi(val);
142         if (ival < 0)
143             return "Smax must be a positive number";
144         worker->smax = ival;
145     }
146     else if (!strcasecmp(key, "acquire")) {
147         /* Acquire timeout in milliseconds.
148          * If set this will be the maximum time to
149          * wait for a free connection.
150          */
151         ival = atoi(val);
152         if (ival < 1)
153             return "Acquire must be at least one mili second";
154         worker->acquire = apr_time_make(0, ival * 1000);
155         worker->acquire_set = 1;
156     }
157     else if (!strcasecmp(key, "timeout")) {
158         /* Connection timeout in seconds.
159          * Defaults to server timeout.
160          */
161         ival = atoi(val);
162         if (ival < 1)
163             return "Timeout must be at least one second";
164         worker->timeout = apr_time_from_sec(ival);
165         worker->timeout_set = 1;
166     }
167     else if (!strcasecmp(key, "iobuffersize")) {
168         long s = atol(val);
169         worker->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
170         worker->io_buffer_size_set = 1;
171     }
172     else if (!strcasecmp(key, "receivebuffersize")) {
173         ival = atoi(val);
174         if (ival < 512 && ival != 0) {
175             return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
176         }
177         worker->recv_buffer_size = ival;
178         worker->recv_buffer_size_set = 1;
179     }
180     else if (!strcasecmp(key, "keepalive")) {
181         if (!strcasecmp(val, "on"))
182             worker->keepalive = 1;
183         else if (!strcasecmp(val, "off"))
184             worker->keepalive = 0;
185         else
186             return "KeepAlive must be On|Off";
187         worker->keepalive_set = 1;
188     }    
189     else if (!strcasecmp(key, "route")) {
190         /* Worker route.
191          */
192         worker->route = apr_pstrdup(p, val);
193     }
194     else if (!strcasecmp(key, "redirect")) {
195         /* Worker redirection route.
196          */
197         worker->redirect = apr_pstrdup(p, val);
198     }
199     else {
200         return "unknown Worker parameter";
201     }
202     return NULL;
203 }
204
205 static const char *set_balancer_param(apr_pool_t *p,
206                                       proxy_balancer *balancer,
207                                       const char *key,
208                                       const char *val)
209 {
210
211     int ival;
212     if (!strcasecmp(key, "stickysession")) {
213         /* Balancer sticky session name.
214          * Set to something like JSESSIONID or
215          * PHPSESSIONID, etc..,
216          */
217         balancer->sticky = apr_pstrdup(p, val);
218     }
219     else if (!strcasecmp(key, "nofailover")) {
220         /* If set to 'on' the session will break
221          * if the worker is in error state or
222          * disabled.
223          */
224         if (!strcasecmp(val, "on"))
225             balancer->sticky_force = 1;
226         else if (!strcasecmp(val, "off"))
227             balancer->sticky_force = 0;
228         else
229             return "failover must be On|Off";
230     }
231     else if (!strcasecmp(key, "timeout")) {
232         /* Balancer timeout in seconds.
233          * If set this will be the maximum time to
234          * wait for a free worker.
235          * Default is not to wait.
236          */
237         ival = atoi(val);
238         if (ival < 1)
239             return "timeout must be at least one second";
240         balancer->timeout = apr_time_from_sec(ival);
241     }
242     else if (!strcasecmp(key, "maxattempts")) {
243         /* Maximum number of failover attempts before
244          * giving up.
245          */
246         ival = atoi(val);
247         if (ival < 0)
248             return "maximum number of attempts must be a positive number";
249         balancer->max_attempts = ival;
250         balancer->max_attempts_set = 1;
251     }
252     else {
253         return "unknown Balancer parameter";
254     }
255     return NULL;
256 }
257
258 static int alias_match(const char *uri, const char *alias_fakename)
259 {
260     const char *end_fakename = alias_fakename + strlen(alias_fakename);
261     const char *aliasp = alias_fakename, *urip = uri;
262     const char *end_uri = uri + strlen(uri);
263     unsigned char uric, aliasc;
264
265     while (aliasp < end_fakename && urip < end_uri) {
266         if (*aliasp == '/') {
267             /* any number of '/' in the alias matches any number in
268              * the supplied URI, but there must be at least one...
269              */
270             if (*urip != '/')
271                 return 0;
272
273             while (*aliasp == '/')
274                 ++aliasp;
275             while (*urip == '/')
276                 ++urip;
277         }
278         else {
279 #ifndef FIX_15207
280             /* Other characters are compared literally */
281             if (*urip++ != *aliasp++)
282                 return 0;
283 #else
284             /* Other characters are canonicalised and compared literally */
285             if (*urip == '%') {
286                 uric = hex2c(urip);
287                 urip += 3;
288             } else {
289                 uric = (unsigned char)*urip++;
290             }
291             if (*aliasp == '%') {
292                 aliasc = hex2c(aliasp);
293                 aliasp += 3;
294             } else {
295                 aliasc = (unsigned char)*aliasp++;
296             }
297             if (uric != aliasc) {
298                 return 0;
299             }
300 #endif
301         }
302     }
303
304     /* fixup badly encoded stuff (e.g. % as last character) */
305     if (aliasp > end_fakename) {
306         aliasp = end_fakename;
307     }
308     if (urip > end_uri) {
309         urip = end_uri;
310     }
311
312    /* We reach the end of the uri before the end of "alias_fakename"
313     * for example uri is "/" and alias_fakename "/examples"
314     */
315    if (urip == end_uri && aliasp!=end_fakename) {
316        return 0;
317    }
318
319     /* Check last alias path component matched all the way */
320     if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
321         return 0;
322
323     /* Return number of characters from URI which matched (may be
324      * greater than length of alias, since we may have matched
325      * doubled slashes)
326      */
327
328     return urip - uri;
329 }
330
331 /* Detect if an absoluteURI should be proxied or not.  Note that we
332  * have to do this during this phase because later phases are
333  * "short-circuiting"... i.e. translate_names will end when the first
334  * module returns OK.  So for example, if the request is something like:
335  *
336  * GET http://othervhost/cgi-bin/printenv HTTP/1.0
337  *
338  * mod_alias will notice the /cgi-bin part and ScriptAlias it and
339  * short-circuit the proxy... just because of the ordering in the
340  * configuration file.
341  */
342 static int proxy_detect(request_rec *r)
343 {
344     void *sconf = r->server->module_config;
345     proxy_server_conf *conf =
346         (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
347 #ifdef FIX_15207
348     int i, len;
349     struct proxy_alias *ent = (struct proxy_alias *)conf->aliases->elts;
350 #endif
351
352     /* Ick... msvc (perhaps others) promotes ternary short results to int */
353
354     if (conf->req && r->parsed_uri.scheme) {
355         /* but it might be something vhosted */
356         if (!(r->parsed_uri.hostname
357               && !strcasecmp(r->parsed_uri.scheme, ap_http_method(r))
358               && ap_matches_request_vhost(r, r->parsed_uri.hostname,
359                                           (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port 
360                                                        : ap_default_port(r))))) {
361             r->proxyreq = PROXYREQ_PROXY;
362             r->uri = r->unparsed_uri;
363             r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
364             r->handler = "proxy-server";
365         }
366     }
367     /* We need special treatment for CONNECT proxying: it has no scheme part */
368     else if (conf->req && r->method_number == M_CONNECT
369              && r->parsed_uri.hostname
370              && r->parsed_uri.port_str) {
371         r->proxyreq = PROXYREQ_PROXY;
372         r->uri = r->unparsed_uri;
373         r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
374         r->handler = "proxy-server";
375 #ifdef FIX_15207
376     } else {
377         /* test for a ProxyPass */
378         for (i = 0; i < conf->aliases->nelts; i++) {
379             len = alias_match(r->unparsed_uri, ent[i].fake);
380             if (len > 0) {
381                 r->filename = apr_pstrcat(r->pool, "proxy:", ent[i].real,
382                                           r->unparsed_uri + len, NULL);
383                 r->handler = "proxy-server";
384                 r->proxyreq = PROXYREQ_REVERSE;
385                 r->uri = r->unparsed_uri;
386                 break;
387             }
388         }
389 #endif
390     }
391     return DECLINED;
392 }
393
394 static int proxy_trans(request_rec *r)
395 {
396 #ifndef FIX_15207
397     void *sconf = r->server->module_config;
398     proxy_server_conf *conf =
399     (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
400     int i, len;
401     struct proxy_alias *ent = (struct proxy_alias *) conf->aliases->elts;
402 #endif
403
404     if (r->proxyreq) {
405         /* someone has already set up the proxy, it was possibly ourselves
406          * in proxy_detect
407          */
408         return OK;
409     }
410
411 #ifndef FIX_15207
412     /* XXX: since r->uri has been manipulated already we're not really
413      * compliant with RFC1945 at this point.  But this probably isn't
414      * an issue because this is a hybrid proxy/origin server.
415      */
416
417     for (i = 0; i < conf->aliases->nelts; i++) {
418         len = alias_match(r->uri, ent[i].fake);
419
420        if (len > 0) {
421            if ((ent[i].real[0] == '!') && (ent[i].real[1] == 0)) {
422                return DECLINED;
423            }
424
425            r->filename = apr_pstrcat(r->pool, "proxy:", ent[i].real,
426                                      r->uri + len, NULL);
427            r->handler = "proxy-server";
428            r->proxyreq = PROXYREQ_REVERSE;
429            return OK;
430        }
431     }
432 #endif
433     return DECLINED;
434 }
435
436 static int proxy_walk(request_rec *r)
437 {
438     proxy_server_conf *sconf = ap_get_module_config(r->server->module_config,
439                                                     &proxy_module);
440     ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
441     ap_conf_vector_t **sec_proxy = (ap_conf_vector_t **) sconf->sec_proxy->elts;
442     ap_conf_vector_t *entry_config;
443     proxy_dir_conf *entry_proxy;
444     int num_sec = sconf->sec_proxy->nelts;
445     /* XXX: shouldn't we use URI here?  Canonicalize it first?
446      * Pass over "proxy:" prefix 
447      */
448     const char *proxyname = r->filename + 6;
449     int j;
450
451     for (j = 0; j < num_sec; ++j) 
452     {
453         entry_config = sec_proxy[j];
454         entry_proxy = ap_get_module_config(entry_config, &proxy_module);
455
456         /* XXX: What about case insensitive matching ???
457          * Compare regex, fnmatch or string as appropriate
458          * If the entry doesn't relate, then continue 
459          */
460         if (entry_proxy->r 
461               ? ap_regexec(entry_proxy->r, proxyname, 0, NULL, 0)
462               : (entry_proxy->p_is_fnmatch
463                    ? apr_fnmatch(entry_proxy->p, proxyname, 0)
464                    : strncmp(proxyname, entry_proxy->p, 
465                                         strlen(entry_proxy->p)))) {
466             continue;
467         }
468         per_dir_defaults = ap_merge_per_dir_configs(r->pool, per_dir_defaults,
469                                                              entry_config);
470     }
471
472     r->per_dir_config = per_dir_defaults;
473
474     return OK;
475 }
476
477 static int proxy_map_location(request_rec *r)
478 {
479     int access_status;
480
481     if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
482         return DECLINED;
483
484     /* Don't let the core or mod_http map_to_storage hooks handle this,
485      * We don't need directory/file_walk, and we want to TRACE on our own.
486      */
487     if ((access_status = proxy_walk(r))) {
488         ap_die(access_status, r);
489         return access_status;
490     }
491
492     return OK;
493 }
494 #ifndef FIX_15207
495 /* -------------------------------------------------------------- */
496 /* Fixup the filename */
497
498 /*
499  * Canonicalise the URL
500  */
501 static int proxy_fixup(request_rec *r)
502 {
503     char *url, *p;
504     int access_status;
505
506     if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
507         return DECLINED;
508
509 #ifdef FIX_15207
510 /* We definitely shouldn't canonicalize a proxy_pass.
511  * But should we really canonicalize a STD_PROXY??? -- Fahree
512  */
513     if (r->proxyreq == PROXYREQ_REVERSE) {
514         return OK;
515     }
516 #endif
517
518     /* XXX: Shouldn't we try this before we run the proxy_walk? */
519     url = &r->filename[6];
520
521     /* canonicalise each specific scheme */
522     if ((access_status = proxy_run_canon_handler(r, url))) {
523         return access_status;
524     }
525
526     p = strchr(url, ':');
527     if (p == NULL || p == url)
528         return HTTP_BAD_REQUEST;
529
530     return OK;      /* otherwise; we've done the best we can */
531 }
532 #endif
533 /* Send a redirection if the request contains a hostname which is not */
534 /* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
535 /* servers like Netscape's allow this and access hosts from the local */
536 /* domain in this case. I think it is better to redirect to a FQDN, since */
537 /* these will later be found in the bookmarks files. */
538 /* The "ProxyDomain" directive determines what domain will be appended */
539 static int proxy_needsdomain(request_rec *r, const char *url, const char *domain)
540 {
541     char *nuri;
542     const char *ref;
543
544     /* We only want to worry about GETs */
545     if (!r->proxyreq || r->method_number != M_GET || !r->parsed_uri.hostname)
546         return DECLINED;
547
548     /* If host does contain a dot already, or it is "localhost", decline */
549     if (strchr(r->parsed_uri.hostname, '.') != NULL
550      || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
551         return DECLINED;    /* host name has a dot already */
552
553     ref = apr_table_get(r->headers_in, "Referer");
554
555     /* Reassemble the request, but insert the domain after the host name */
556     /* Note that the domain name always starts with a dot */
557     r->parsed_uri.hostname = apr_pstrcat(r->pool, r->parsed_uri.hostname,
558                                          domain, NULL);
559     nuri = apr_uri_unparse(r->pool,
560                            &r->parsed_uri,
561                            APR_URI_UNP_REVEALPASSWORD);
562
563     apr_table_set(r->headers_out, "Location", nuri);
564     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
565                   "Domain missing: %s sent to %s%s%s", r->uri,
566                   apr_uri_unparse(r->pool, &r->parsed_uri,
567                                   APR_URI_UNP_OMITUSERINFO),
568                   ref ? " from " : "", ref ? ref : "");
569
570     return HTTP_MOVED_PERMANENTLY;
571 }
572
573 /* -------------------------------------------------------------- */
574 /* Invoke handler */
575
576 static int proxy_handler(request_rec *r)
577 {
578     char *url, *scheme, *p;
579     const char *p2;
580     void *sconf = r->server->module_config;
581     proxy_server_conf *conf = (proxy_server_conf *)
582         ap_get_module_config(sconf, &proxy_module);
583     apr_array_header_t *proxies = conf->proxies;
584     struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
585     int i, rc, access_status;
586     int direct_connect = 0;
587     const char *str;
588     long maxfwd;
589     proxy_balancer *balancer = NULL;
590     proxy_worker *worker = NULL;
591     int attempts = 0, max_attempts = 0;
592
593     /* is this for us? */
594     if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
595         return DECLINED;
596
597     /* handle max-forwards / OPTIONS / TRACE */
598     if ((str = apr_table_get(r->headers_in, "Max-Forwards"))) {
599         maxfwd = strtol(str, NULL, 10);
600         if (maxfwd < 1) {
601             switch (r->method_number) {
602             case M_TRACE: {
603                 int access_status;
604                 r->proxyreq = PROXYREQ_NONE;
605                 if ((access_status = ap_send_http_trace(r)))
606                     ap_die(access_status, r);
607                 else
608                     ap_finalize_request_protocol(r);
609                 return OK;
610             }
611             case M_OPTIONS: {
612                 int access_status;
613                 r->proxyreq = PROXYREQ_NONE;
614                 if ((access_status = ap_send_http_options(r)))
615                     ap_die(access_status, r);
616                 else
617                     ap_finalize_request_protocol(r);
618                 return OK;
619             }
620             default: {
621                 return ap_proxyerror(r, HTTP_BAD_GATEWAY,
622                                      "Max-Forwards has reached zero - proxy loop?");
623             }
624             }
625         }
626         maxfwd = (maxfwd > 0) ? maxfwd - 1 : 0;
627     }
628     else {
629         /* set configured max-forwards */
630         maxfwd = conf->maxfwd;
631     }
632     apr_table_set(r->headers_in, "Max-Forwards", 
633                   apr_psprintf(r->pool, "%ld", (maxfwd > 0) ? maxfwd : 0));
634
635     do {
636         url = r->filename + 6;
637         p = strchr(url, ':');
638         if (p == NULL) {
639             ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
640                           "proxy_handler no URL in %s", r->filename);
641             return HTTP_BAD_REQUEST;
642         }
643
644         /* If the host doesn't have a domain name, add one and redirect. */
645         if (conf->domain != NULL) {
646             rc = proxy_needsdomain(r, url, conf->domain);
647             if (ap_is_HTTP_REDIRECT(rc))
648                 return HTTP_MOVED_PERMANENTLY;
649         }
650
651         *p = '\0';
652         scheme = apr_pstrdup(r->pool, url);
653         *p = ':';
654
655         /* Check URI's destination host against NoProxy hosts */
656         /* Bypass ProxyRemote server lookup if configured as NoProxy */
657         /* we only know how to handle communication to a proxy via http */
658         /*if (strcasecmp(scheme, "http") == 0) */
659         {
660             int ii;
661             struct dirconn_entry *list = (struct dirconn_entry *)
662                                                 conf->dirconn->elts;
663
664             for (direct_connect = ii = 0; ii < conf->dirconn->nelts &&
665                                                !direct_connect; ii++) {
666                 direct_connect = list[ii].matcher(&list[ii], r);
667             }
668 #if DEBUGGING
669             ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
670                       (direct_connect) ? "NoProxy for %s" : "UseProxy for %s",
671                       r->uri);
672 #endif
673         }
674     
675         /* Try to obtain the most suitable worker */
676         access_status = ap_proxy_pre_request(&worker, &balancer, r, conf, &url);
677         if (access_status != OK)
678             return access_status;
679         if (balancer && balancer->max_attempts_set && !max_attempts)
680             max_attempts = balancer->max_attempts;
681         /* firstly, try a proxy, unless a NoProxy directive is active */
682         if (!direct_connect) {
683             for (i = 0; i < proxies->nelts; i++) {
684                 p2 = ap_strchr_c(ents[i].scheme, ':');  /* is it a partial URL? */
685                 if (strcmp(ents[i].scheme, "*") == 0 ||
686                     (ents[i].use_regex && ap_regexec(ents[i].regexp, url,
687                                                      0,NULL, 0)) ||
688                     (p2 == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
689                     (p2 != NULL &&
690                     strncasecmp(url, ents[i].scheme,
691                                 strlen(ents[i].scheme)) == 0)) {
692
693                     /* handle the scheme */
694                     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
695                                  "Trying to run scheme_handler against proxy");
696                     access_status = proxy_run_scheme_handler(r, worker,
697                                                              conf, url,
698                                                              ents[i].hostname,
699                                                              ents[i].port);
700
701                     /* an error or success */
702                     if (access_status != DECLINED &&
703                         access_status != HTTP_BAD_GATEWAY) {
704                         goto cleanup;
705                     }
706                     /* we failed to talk to the upstream proxy */
707                 }
708             }
709         }
710
711         /* otherwise, try it direct */
712         /* N.B. what if we're behind a firewall, where we must use a proxy or
713         * give up??
714         */
715
716         /* handle the scheme */
717         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
718                      "Running scheme %s handler (attempt %d)",
719                      scheme, attempts);
720         if ((access_status = proxy_run_scheme_handler(r, worker, conf,
721                                                       url, NULL, 0)) == OK)
722             break;
723         
724     } while (!PROXY_WORKER_IS_USABLE(worker) && 
725              max_attempts > attempts++);
726
727     if (DECLINED == access_status) {
728         ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
729                     "proxy: No protocol handler was valid for the URL %s. "
730                     "If you are using a DSO version of mod_proxy, make sure "
731                     "the proxy submodules are included in the configuration "
732                     "using LoadModule.", r->uri);
733         access_status = HTTP_FORBIDDEN;
734         goto cleanup;
735     }
736 cleanup:
737     if (balancer) {
738         int post_status = proxy_run_post_request(worker, balancer, r, conf);
739         if (post_status == DECLINED) {
740             post_status = OK; /* no post_request handler available */
741             /* TODO: reclycle direct worker */
742         }
743     }
744     return access_status;
745 }
746
747 /* -------------------------------------------------------------- */
748 /* Setup configurable data */
749
750 static void * create_proxy_config(apr_pool_t *p, server_rec *s)
751 {
752     proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
753
754     ps->sec_proxy = apr_array_make(p, 10, sizeof(ap_conf_vector_t *));
755     ps->proxies = apr_array_make(p, 10, sizeof(struct proxy_remote));
756     ps->aliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
757     ps->raliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
758     ps->cookie_paths = apr_array_make(p, 10, sizeof(struct proxy_alias));
759     ps->cookie_domains = apr_array_make(p, 10, sizeof(struct proxy_alias));
760     ps->cookie_path_str = apr_strmatch_precompile(p, "path=", 0);
761     ps->cookie_domain_str = apr_strmatch_precompile(p, "domain=", 0);
762     ps->noproxies = apr_array_make(p, 10, sizeof(struct noproxy_entry));
763     ps->dirconn = apr_array_make(p, 10, sizeof(struct dirconn_entry));
764     ps->allowed_connect_ports = apr_array_make(p, 10, sizeof(int));
765     ps->workers = apr_array_make(p, 10, sizeof(proxy_worker));
766     ps->balancers = apr_array_make(p, 10, sizeof(proxy_balancer));
767     ps->forward = NULL;
768     ps->domain = NULL;
769     ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
770     ps->viaopt_set = 0; /* 0 means default */
771     ps->req = 0;
772     ps->req_set = 0;
773     ps->recv_buffer_size = 0; /* this default was left unset for some reason */
774     ps->recv_buffer_size_set = 0;
775     ps->io_buffer_size = AP_IOBUFSIZE;
776     ps->io_buffer_size_set = 0;
777     ps->maxfwd = DEFAULT_MAX_FORWARDS;
778     ps->maxfwd_set = 0;
779     ps->error_override = 0; 
780     ps->error_override_set = 0; 
781     ps->preserve_host_set = 0;
782     ps->preserve_host = 0;    
783     ps->timeout = 0;
784     ps->timeout_set = 0;
785     ps->badopt = bad_error;
786     ps->badopt_set = 0;
787     ps->pool = p;
788     return ps;
789 }
790
791 static void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
792 {
793     proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
794     proxy_server_conf *base = (proxy_server_conf *) basev;
795     proxy_server_conf *overrides = (proxy_server_conf *) overridesv;
796
797     ps->proxies = apr_array_append(p, base->proxies, overrides->proxies);
798     ps->sec_proxy = apr_array_append(p, base->sec_proxy, overrides->sec_proxy);
799     ps->aliases = apr_array_append(p, base->aliases, overrides->aliases);
800     ps->raliases = apr_array_append(p, base->raliases, overrides->raliases);
801     ps->cookie_paths
802         = apr_array_append(p, base->cookie_paths, overrides->cookie_paths);
803     ps->cookie_domains
804         = apr_array_append(p, base->cookie_domains, overrides->cookie_domains);
805     ps->cookie_path_str = base->cookie_path_str;
806     ps->cookie_domain_str = base->cookie_domain_str;
807     ps->noproxies = apr_array_append(p, base->noproxies, overrides->noproxies);
808     ps->dirconn = apr_array_append(p, base->dirconn, overrides->dirconn);
809     ps->allowed_connect_ports = apr_array_append(p, base->allowed_connect_ports, overrides->allowed_connect_ports);
810     ps->workers = apr_array_append(p, base->workers, overrides->workers);
811     ps->balancers = apr_array_append(p, base->balancers, overrides->balancers);
812     ps->forward = overrides->forward ? overrides->forward : base->forward;
813
814     ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain;
815     ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt;
816     ps->req = (overrides->req_set == 0) ? base->req : overrides->req;
817     ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size;
818     ps->io_buffer_size = (overrides->io_buffer_size_set == 0) ? base->io_buffer_size : overrides->io_buffer_size;
819     ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd;
820     ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override;
821     ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host;
822     ps->timeout= (overrides->timeout_set == 0) ? base->timeout : overrides->timeout;
823     ps->badopt = (overrides->badopt_set == 0) ? base->badopt : overrides->badopt;
824     ps->pool = p;
825     return ps;
826 }
827
828 static void *create_proxy_dir_config(apr_pool_t *p, char *dummy)
829 {
830     proxy_dir_conf *new =
831         (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
832
833     /* Filled in by proxysection, when applicable */
834
835     return (void *) new;
836 }
837
838 static void *merge_proxy_dir_config(apr_pool_t *p, void *basev, void *addv)
839 {
840     proxy_dir_conf *new = (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
841     proxy_dir_conf *add = (proxy_dir_conf *) addv;
842
843     new->p = add->p;
844     new->p_is_fnmatch = add->p_is_fnmatch;
845     new->r = add->r;
846     return new;
847 }
848
849
850 static const char *
851     add_proxy(cmd_parms *cmd, void *dummy, const char *f1, const char *r1, int regex)
852 {
853     server_rec *s = cmd->server;
854     proxy_server_conf *conf =
855     (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
856     struct proxy_remote *new;
857     char *p, *q;
858     char *r, *f, *scheme;
859     regex_t *reg = NULL;
860     int port;
861
862     r = apr_pstrdup(cmd->pool, r1);
863     scheme = apr_pstrdup(cmd->pool, r1);
864     f = apr_pstrdup(cmd->pool, f1);
865     p = strchr(r, ':');
866     if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0') {
867         if (regex)
868             return "ProxyRemoteMatch: Bad syntax for a remote proxy server";
869         else
870             return "ProxyRemote: Bad syntax for a remote proxy server";
871     }
872     else {
873         scheme[p-r] = 0;
874     }
875     q = strchr(p + 3, ':');
876     if (q != NULL) {
877         if (sscanf(q + 1, "%u", &port) != 1 || port > 65535) {
878             if (regex)
879                 return "ProxyRemoteMatch: Bad syntax for a remote proxy server (bad port number)";
880             else
881                 return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";
882         }
883         *q = '\0';
884     }
885     else
886         port = -1;
887     *p = '\0';
888     if (regex) {
889         reg = ap_pregcomp(cmd->pool, f, REG_EXTENDED);
890         if (!reg)
891             return "Regular expression for ProxyRemoteMatch could not be compiled.";
892     }
893     else
894         if (strchr(f, ':') == NULL)
895             ap_str_tolower(f);      /* lowercase scheme */
896     ap_str_tolower(p + 3);      /* lowercase hostname */
897
898     if (port == -1) {
899         port = apr_uri_port_of_scheme(scheme);
900     }
901
902     new = apr_array_push(conf->proxies);
903     new->scheme = f;
904     new->protocol = r;
905     new->hostname = p + 3;
906     new->port = port;
907     new->regexp = reg;
908     new->use_regex = regex;
909     return NULL;
910 }
911
912 static const char *
913     add_proxy_noregex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
914 {
915     return add_proxy(cmd, dummy, f1, r1, 0);
916 }
917
918 static const char *
919     add_proxy_regex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
920 {
921     return add_proxy(cmd, dummy, f1, r1, 1);
922 }
923
924 static const char *
925     add_pass(cmd_parms *cmd, void *dummy, const char *arg)
926 {
927     server_rec *s = cmd->server;
928     proxy_server_conf *conf =
929     (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
930     struct proxy_alias *new;
931     char *f = cmd->path;
932     char *r = NULL;
933     char *word;
934     apr_table_t *params = apr_table_make(cmd->pool, 5);
935     const apr_array_header_t *arr;
936     const apr_table_entry_t *elts;
937     int i;
938     
939     while (*arg) {
940         word = ap_getword_conf(cmd->pool, &arg);
941         if (!f)
942             f = word;
943         else if (!r)
944             r = word;
945         else {
946             char *val = strchr(word, '=');
947             if (!val) {
948                 if (cmd->path)
949                     return "Invalid ProxyPass parameter.  Parameter must be "
950                            "in the form 'key=value'";
951                 else
952                     return "ProxyPass can not have a path when defined in a location"; 
953             }
954             else
955                 *val++ = '\0';
956             apr_table_setn(params, word, val);
957         }
958     };
959
960     if (r == NULL)
961         return "ProxyPass needs a path when not defined in a location";
962
963     new = apr_array_push(conf->aliases);
964     new->fake = apr_pstrdup(cmd->pool, f);
965     new->real = apr_pstrdup(cmd->pool, r);
966     
967     arr = apr_table_elts(params);
968     elts = (const apr_table_entry_t *)arr->elts;
969     /* Distinguish the balancer from woker */
970     if (strncasecmp(r, "balancer:", 9) == 0) {
971         proxy_balancer *balancer = ap_proxy_get_balancer(cmd->pool, conf, r);
972         if (!balancer) {
973             const char *err = ap_proxy_add_balancer(&balancer,
974                                                     cmd->pool,
975                                                     conf, r);
976             if (err)
977                 return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
978         }        
979         for (i = 0; i < arr->nelts; i++) {
980             const char *err = set_balancer_param(cmd->pool, balancer, elts[i].key,
981                                                  elts[i].val);
982             if (err)
983                 return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
984         }
985     }
986     else {
987         proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, conf, r);
988         if (!worker) {
989             const char *err = ap_proxy_add_worker(&worker, cmd->pool, conf, r);
990             if (err)
991                 return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
992         }
993         PROXY_COPY_CONF_PARAMS(worker, conf);
994
995         for (i = 0; i < arr->nelts; i++) {
996             const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
997                                                elts[i].val);
998             if (err)
999                 return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
1000         }
1001     }
1002     return NULL;
1003 }
1004
1005 static const char *
1006     add_pass_reverse(cmd_parms *cmd, void *dummy, const char *f, const char *r)
1007 {
1008     server_rec *s = cmd->server;
1009     proxy_server_conf *conf;
1010     struct proxy_alias *new;
1011
1012     conf = (proxy_server_conf *)ap_get_module_config(s->module_config, 
1013                                                      &proxy_module);
1014     if (r!=NULL && cmd->path == NULL ) {
1015         new = apr_array_push(conf->raliases);
1016         new->fake = f;
1017         new->real = r;
1018     } else if (r==NULL && cmd->path != NULL) {
1019         new = apr_array_push(conf->raliases);
1020         new->fake = cmd->path;
1021         new->real = f;
1022     } else {
1023         if ( r == NULL)
1024             return "ProxyPassReverse needs a path when not defined in a location";
1025         else 
1026             return "ProxyPassReverse can not have a path when defined in a location";
1027     }
1028
1029     return NULL;
1030 }
1031 static const char*
1032     cookie_path(cmd_parms *cmd, void *dummy, const char *f, const char *r)
1033 {
1034     server_rec *s = cmd->server;
1035     proxy_server_conf *conf;
1036     struct proxy_alias *new;
1037
1038     conf = (proxy_server_conf *)ap_get_module_config(s->module_config,
1039                                                      &proxy_module);
1040     new = apr_array_push(conf->cookie_paths);
1041     new->fake = f;
1042     new->real = r;
1043
1044     return NULL;
1045 }
1046 static const char*
1047     cookie_domain(cmd_parms *cmd, void *dummy, const char *f, const char *r)
1048 {
1049     server_rec *s = cmd->server;
1050     proxy_server_conf *conf;
1051     struct proxy_alias *new;
1052
1053     conf = (proxy_server_conf *)ap_get_module_config(s->module_config,
1054                                                      &proxy_module);
1055     new = apr_array_push(conf->cookie_domains);
1056     new->fake = f;
1057     new->real = r;
1058
1059     return NULL;
1060 }
1061
1062 static const char *
1063     set_proxy_exclude(cmd_parms *parms, void *dummy, const char *arg)
1064 {
1065     server_rec *s = parms->server;
1066     proxy_server_conf *conf =
1067     ap_get_module_config(s->module_config, &proxy_module);
1068     struct noproxy_entry *new;
1069     struct noproxy_entry *list = (struct noproxy_entry *) conf->noproxies->elts;
1070     struct apr_sockaddr_t *addr;
1071     int found = 0;
1072     int i;
1073
1074     /* Don't duplicate entries */
1075     for (i = 0; i < conf->noproxies->nelts; i++) {
1076         if (apr_strnatcasecmp(arg, list[i].name) == 0) { /* ignore case for host names */
1077             found = 1;
1078         }
1079     }
1080
1081     if (!found) {
1082         new = apr_array_push(conf->noproxies);
1083         new->name = arg;
1084         if (APR_SUCCESS == apr_sockaddr_info_get(&addr, new->name, APR_UNSPEC, 0, 0, parms->pool)) {
1085             new->addr = addr;
1086         }
1087         else {
1088             new->addr = NULL;
1089         }
1090     }
1091     return NULL;
1092 }
1093
1094 /*
1095  * Set the ports CONNECT can use
1096  */
1097 static const char *
1098     set_allowed_ports(cmd_parms *parms, void *dummy, const char *arg)
1099 {
1100     server_rec *s = parms->server;
1101     proxy_server_conf *conf =
1102         ap_get_module_config(s->module_config, &proxy_module);
1103     int *New;
1104
1105     if (!apr_isdigit(arg[0]))
1106         return "AllowCONNECT: port number must be numeric";
1107
1108     New = apr_array_push(conf->allowed_connect_ports);
1109     *New = atoi(arg);
1110     return NULL;
1111 }
1112
1113 /* Similar to set_proxy_exclude(), but defining directly connected hosts,
1114  * which should never be accessed via the configured ProxyRemote servers
1115  */
1116 static const char *
1117     set_proxy_dirconn(cmd_parms *parms, void *dummy, const char *arg)
1118 {
1119     server_rec *s = parms->server;
1120     proxy_server_conf *conf =
1121     ap_get_module_config(s->module_config, &proxy_module);
1122     struct dirconn_entry *New;
1123     struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;
1124     int found = 0;
1125     int i;
1126
1127     /* Don't duplicate entries */
1128     for (i = 0; i < conf->dirconn->nelts; i++) {
1129         if (strcasecmp(arg, list[i].name) == 0)
1130             found = 1;
1131     }
1132
1133     if (!found) {
1134         New = apr_array_push(conf->dirconn);
1135         New->name = apr_pstrdup(parms->pool, arg);
1136         New->hostaddr = NULL;
1137
1138     if (ap_proxy_is_ipaddr(New, parms->pool)) {
1139 #if DEBUGGING
1140         ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1141                      "Parsed addr %s", inet_ntoa(New->addr));
1142         ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1143                      "Parsed mask %s", inet_ntoa(New->mask));
1144 #endif
1145     }
1146     else if (ap_proxy_is_domainname(New, parms->pool)) {
1147         ap_str_tolower(New->name);
1148 #if DEBUGGING
1149         ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1150                      "Parsed domain %s", New->name);
1151 #endif
1152         }
1153         else if (ap_proxy_is_hostname(New, parms->pool)) {
1154             ap_str_tolower(New->name);
1155 #if DEBUGGING
1156             ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
1157                          "Parsed host %s", New->name);
1158 #endif
1159         }
1160         else {
1161             ap_proxy_is_word(New, parms->pool);
1162 #if DEBUGGING
1163             fprintf(stderr, "Parsed word %s\n", New->name);
1164 #endif
1165         }
1166     }
1167     return NULL;
1168 }
1169
1170 static const char *
1171     set_proxy_domain(cmd_parms *parms, void *dummy, const char *arg)
1172 {
1173     proxy_server_conf *psf =
1174     ap_get_module_config(parms->server->module_config, &proxy_module);
1175
1176     if (arg[0] != '.')
1177         return "ProxyDomain: domain name must start with a dot.";
1178
1179     psf->domain = arg;
1180     return NULL;
1181 }
1182
1183 static const char *
1184     set_proxy_req(cmd_parms *parms, void *dummy, int flag)
1185 {
1186     proxy_server_conf *psf =
1187     ap_get_module_config(parms->server->module_config, &proxy_module);
1188
1189     psf->req = flag;
1190     psf->req_set = 1;
1191
1192     if (flag && !psf->forward) {
1193         psf->forward = ap_proxy_create_worker(parms->pool);
1194         psf->forward->name     = "proxy:forward";
1195         psf->forward->hostname = "*";
1196         psf->forward->scheme   = "*";
1197
1198         /* Do not disable worker in case of errors */
1199         psf->forward->status = PROXY_WORKER_IGNORE_ERRORS;
1200     }
1201     return NULL;
1202 }
1203
1204 static const char *
1205     set_proxy_error_override(cmd_parms *parms, void *dummy, int flag)
1206 {
1207     proxy_server_conf *psf =
1208     ap_get_module_config(parms->server->module_config, &proxy_module);
1209
1210     psf->error_override = flag;
1211     psf->error_override_set = 1;
1212     return NULL;
1213 }
1214 static const char *
1215     set_preserve_host(cmd_parms *parms, void *dummy, int flag)
1216 {
1217     proxy_server_conf *psf =
1218     ap_get_module_config(parms->server->module_config, &proxy_module);
1219
1220     psf->preserve_host = flag;
1221     psf->preserve_host_set = 1;
1222     return NULL;
1223 }
1224
1225 static const char *
1226     set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
1227 {
1228     proxy_server_conf *psf =
1229     ap_get_module_config(parms->server->module_config, &proxy_module);
1230     int s = atoi(arg);
1231     if (s < 512 && s != 0) {
1232         return "ProxyReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
1233     }
1234
1235     psf->recv_buffer_size = s;
1236     psf->recv_buffer_size_set = 1;
1237     return NULL;
1238 }
1239
1240 static const char *
1241     set_io_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
1242 {
1243     proxy_server_conf *psf =
1244     ap_get_module_config(parms->server->module_config, &proxy_module);
1245     long s = atol(arg);
1246
1247     psf->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
1248     psf->io_buffer_size_set = 1;
1249     return NULL;
1250 }
1251
1252 static const char *
1253     set_max_forwards(cmd_parms *parms, void *dummy, const char *arg)
1254 {
1255     proxy_server_conf *psf =
1256     ap_get_module_config(parms->server->module_config, &proxy_module);
1257     long s = atol(arg);
1258     if (s < 0) {
1259         return "ProxyMaxForwards must be greater or equal to zero..";
1260     }
1261
1262     psf->maxfwd = s;
1263     psf->maxfwd_set = 1;
1264     return NULL;
1265 }
1266 static const char*
1267     set_proxy_timeout(cmd_parms *parms, void *dummy, const char *arg)
1268 {
1269     proxy_server_conf *psf =
1270     ap_get_module_config(parms->server->module_config, &proxy_module);
1271     int timeout;
1272
1273     timeout=atoi(arg);
1274     if (timeout<1) {
1275         return "Proxy Timeout must be at least 1 second.";
1276     }
1277     psf->timeout_set=1;
1278     psf->timeout=apr_time_from_sec(timeout);
1279
1280     return NULL;    
1281 }
1282
1283 static const char*
1284     set_via_opt(cmd_parms *parms, void *dummy, const char *arg)
1285 {
1286     proxy_server_conf *psf =
1287     ap_get_module_config(parms->server->module_config, &proxy_module);
1288
1289     if (strcasecmp(arg, "Off") == 0)
1290         psf->viaopt = via_off;
1291     else if (strcasecmp(arg, "On") == 0)
1292         psf->viaopt = via_on;
1293     else if (strcasecmp(arg, "Block") == 0)
1294         psf->viaopt = via_block;
1295     else if (strcasecmp(arg, "Full") == 0)
1296         psf->viaopt = via_full;
1297     else {
1298         return "ProxyVia must be one of: "
1299             "off | on | full | block";
1300     }
1301
1302     psf->viaopt_set = 1;
1303     return NULL;    
1304 }
1305
1306 static const char*
1307     set_bad_opt(cmd_parms *parms, void *dummy, const char *arg)
1308 {
1309     proxy_server_conf *psf =
1310     ap_get_module_config(parms->server->module_config, &proxy_module);
1311
1312     if (strcasecmp(arg, "IsError") == 0)
1313         psf->badopt = bad_error;
1314     else if (strcasecmp(arg, "Ignore") == 0)
1315         psf->badopt = bad_ignore;
1316     else if (strcasecmp(arg, "StartBody") == 0)
1317         psf->badopt = bad_body;
1318     else {
1319         return "ProxyBadHeader must be one of: "
1320             "IsError | Ignore | StartBody";
1321     }
1322
1323     psf->badopt_set = 1;
1324     return NULL;    
1325 }
1326
1327 static const char*
1328     set_status_opt(cmd_parms *parms, void *dummy, const char *arg)
1329 {
1330     proxy_server_conf *psf =
1331     ap_get_module_config(parms->server->module_config, &proxy_module);
1332
1333     if (strcasecmp(arg, "Off") == 0)
1334         psf->proxy_status = status_off;
1335     else if (strcasecmp(arg, "On") == 0)
1336         psf->proxy_status = status_on;
1337     else if (strcasecmp(arg, "Full") == 0)
1338         psf->proxy_status = status_full;
1339     else {
1340         return "ProxyStatus must be one of: "
1341             "off | on | block";
1342     }
1343
1344     psf->proxy_status_set = 1;
1345     return NULL;    
1346 }
1347
1348 static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
1349 {
1350     server_rec *s = cmd->server;
1351     proxy_server_conf *conf =
1352     ap_get_module_config(s->module_config, &proxy_module);
1353     proxy_balancer *balancer;
1354     proxy_worker *worker;
1355     char *path = cmd->path;
1356     char *name = NULL;
1357     char *word;
1358     apr_table_t *params = apr_table_make(cmd->pool, 5);
1359     const apr_array_header_t *arr;
1360     const apr_table_entry_t *elts;
1361     int i;
1362     
1363     if (cmd->path)
1364         path = apr_pstrdup(cmd->pool, cmd->path);
1365     while (*arg) {
1366         word = ap_getword_conf(cmd->pool, &arg);
1367         if (!path)
1368             path = word;
1369         else if (!name)
1370             name = word;
1371         else {
1372             char *val = strchr(word, '=');
1373             if (!val)
1374                 if (cmd->path)
1375                     return "BalancerMember can not have a balancer name when defined in a location";
1376                 else
1377                     return "Invalid BalancerMember parameter. Parameter must "
1378                            "be in the form 'key=value'";
1379             else
1380                 *val++ = '\0';
1381             apr_table_setn(params, word, val);
1382         }
1383     }
1384     if (!path)
1385         return "BalancerMember must define balancer name when outside <Proxy > section";
1386     if (!name)
1387         return "BalancerMember must define remote proxy server";
1388     
1389     ap_str_tolower(path);   /* lowercase scheme://hostname */
1390     ap_str_tolower(name);   /* lowercase scheme://hostname */
1391
1392     /* Try to find existing worker */
1393     worker = ap_proxy_get_worker(cmd->temp_pool, conf, name);
1394     if (!worker) {
1395         const char *err;
1396         if ((err = ap_proxy_add_worker(&worker, cmd->pool, conf, name)) != NULL)
1397             return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL); 
1398     }
1399     PROXY_COPY_CONF_PARAMS(worker, conf);
1400     
1401     arr = apr_table_elts(params);
1402     elts = (const apr_table_entry_t *)arr->elts;
1403     for (i = 0; i < arr->nelts; i++) {
1404         const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
1405                                            elts[i].val);
1406         if (err)
1407             return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
1408     }
1409     /* Try to find the balancer */
1410     balancer = ap_proxy_get_balancer(cmd->temp_pool, conf, path); 
1411     if (!balancer) {
1412         const char *err = ap_proxy_add_balancer(&balancer,
1413                                                 cmd->pool,
1414                                                 conf, path);
1415         if (err)
1416             return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
1417     }
1418     /* Add the worker to the load balancer */
1419     ap_proxy_add_worker_to_balancer(cmd->pool, balancer, worker);
1420     return NULL;
1421 }
1422
1423 static const char *
1424     set_proxy_param(cmd_parms *cmd, void *dummy, const char *arg)
1425 {
1426     server_rec *s = cmd->server;
1427     proxy_server_conf *conf =
1428     (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
1429     char *name = NULL;
1430     char *word, *val;
1431     proxy_balancer *balancer = NULL;
1432     proxy_worker *worker = NULL;
1433     const char *err;
1434
1435     if (cmd->directive->parent &&
1436         strncasecmp(cmd->directive->parent->directive,
1437                     "<Proxy", 6) == 0) {
1438         const char *pargs = cmd->directive->parent->args;
1439         /* Directive inside <Proxy section
1440          * Parent directive arg is the worker/balancer name.
1441          */
1442         name = ap_getword_conf(cmd->temp_pool, &pargs);
1443         if ((word = ap_strchr(name, '>')))
1444             *word = '\0';
1445     }
1446     else {
1447         /* Standard set directive with worker/balancer
1448          * name as first param.
1449          */
1450         name = ap_getword_conf(cmd->temp_pool, &arg);
1451     }
1452  
1453     if (strncasecmp(name, "balancer:", 9) == 0) {
1454         balancer = ap_proxy_get_balancer(cmd->pool, conf, name);
1455         if (!balancer) {
1456             return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
1457                                name, "' Balancer.", NULL);
1458         }        
1459     }
1460     else {
1461         worker = ap_proxy_get_worker(cmd->temp_pool, conf, name);
1462         if (!worker) {
1463             return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
1464                                name, "' Worker.", NULL);
1465         }
1466     }
1467
1468     while (*arg) {
1469         word = ap_getword_conf(cmd->pool, &arg);
1470         val = strchr(word, '=');
1471         if (!val) {
1472             return "Invalid ProxySet parameter. Parameter must be "
1473                    "in the form 'key=value'";
1474         }
1475         else
1476             *val++ = '\0';
1477         if (worker)
1478             err = set_worker_param(cmd->pool, worker, word, val);
1479         else
1480             err = set_balancer_param(cmd->pool, balancer, word, val);
1481
1482         if (err)
1483             return apr_pstrcat(cmd->temp_pool, "ProxySet ", err, " ", word, " ", name, NULL);
1484     }
1485
1486     return NULL;
1487 }
1488
1489 static void ap_add_per_proxy_conf(server_rec *s, ap_conf_vector_t *dir_config)
1490 {
1491     proxy_server_conf *sconf = ap_get_module_config(s->module_config,
1492                                                     &proxy_module);
1493     void **new_space = (void **)apr_array_push(sconf->sec_proxy);
1494     
1495     *new_space = dir_config;
1496 }
1497
1498 static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
1499 {
1500     const char *errmsg;
1501     const char *endp = ap_strrchr_c(arg, '>');
1502     int old_overrides = cmd->override;
1503     char *old_path = cmd->path;
1504     proxy_dir_conf *conf;
1505     ap_conf_vector_t *new_dir_conf = ap_create_per_dir_config(cmd->pool);
1506     regex_t *r = NULL;
1507     const command_rec *thiscmd = cmd->cmd;
1508
1509     const char *err = ap_check_cmd_context(cmd,
1510                                            NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
1511     if (err != NULL) {
1512         return err;
1513     }
1514
1515     if (endp == NULL) {
1516         return apr_pstrcat(cmd->pool, cmd->cmd->name,
1517                            "> directive missing closing '>'", NULL);
1518     }
1519
1520     arg=apr_pstrndup(cmd->pool, arg, endp-arg);
1521
1522     if (!arg) {
1523         if (thiscmd->cmd_data)
1524             return "<ProxyMatch > block must specify a path";
1525         else
1526             return "<Proxy > block must specify a path";
1527     }
1528
1529     cmd->path = ap_getword_conf(cmd->pool, &arg);
1530     cmd->override = OR_ALL|ACCESS_CONF;
1531
1532     if (!strncasecmp(cmd->path, "proxy:", 6))
1533         cmd->path += 6;
1534
1535     /* XXX Ignore case?  What if we proxy a case-insensitive server?!? 
1536      * While we are at it, shouldn't we also canonicalize the entire
1537      * scheme?  See proxy_fixup()
1538      */
1539     if (thiscmd->cmd_data) { /* <ProxyMatch> */
1540         r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
1541         if (!r) {
1542             return "Regex could not be compiled";
1543         }
1544     }
1545     else if (!strcmp(cmd->path, "~")) {
1546         cmd->path = ap_getword_conf(cmd->pool, &arg);
1547         if (!cmd->path)
1548             return "<Proxy ~ > block must specify a path";
1549         if (strncasecmp(cmd->path, "proxy:", 6))
1550             cmd->path += 6;
1551         r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
1552         if (!r) {
1553             return "Regex could not be compiled";
1554         }
1555     }
1556
1557     /* initialize our config and fetch it */
1558     conf = ap_set_config_vectors(cmd->server, new_dir_conf, cmd->path,
1559                                  &proxy_module, cmd->pool);
1560
1561     errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);
1562     if (errmsg != NULL)
1563         return errmsg;
1564
1565     conf->r = r;
1566     conf->p = cmd->path;
1567     conf->p_is_fnmatch = apr_fnmatch_test(conf->p);
1568
1569     ap_add_per_proxy_conf(cmd->server, new_dir_conf);
1570
1571     if (*arg != '\0') {
1572         return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
1573                            "> arguments not (yet) supported.", NULL);
1574     }
1575
1576     cmd->path = old_path;
1577     cmd->override = old_overrides;
1578
1579     return NULL;
1580 }
1581
1582 static const command_rec proxy_cmds[] =
1583 {
1584     AP_INIT_RAW_ARGS("<Proxy", proxysection, NULL, RSRC_CONF, 
1585     "Container for directives affecting resources located in the proxied "
1586     "location"),
1587     AP_INIT_RAW_ARGS("<ProxyMatch", proxysection, (void*)1, RSRC_CONF,
1588     "Container for directives affecting resources located in the proxied "
1589     "location, in regular expression syntax"),
1590     AP_INIT_FLAG("ProxyRequests", set_proxy_req, NULL, RSRC_CONF,
1591      "on if the true proxy requests should be accepted"),
1592     AP_INIT_TAKE2("ProxyRemote", add_proxy_noregex, NULL, RSRC_CONF,
1593      "a scheme, partial URL or '*' and a proxy server"),
1594     AP_INIT_TAKE2("ProxyRemoteMatch", add_proxy_regex, NULL, RSRC_CONF,
1595      "a regex pattern and a proxy server"),
1596     AP_INIT_RAW_ARGS("ProxyPass", add_pass, NULL, RSRC_CONF|ACCESS_CONF,
1597      "a virtual path and a URL"),
1598     AP_INIT_TAKE12("ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF|ACCESS_CONF,
1599      "a virtual path and a URL for reverse proxy behaviour"),
1600     AP_INIT_TAKE2("ProxyPassReverseCookiePath", cookie_path, NULL,
1601        RSRC_CONF|ACCESS_CONF, "Path rewrite rule for proxying cookies"),
1602     AP_INIT_TAKE2("ProxyPassReverseCookieDomain", cookie_domain, NULL,
1603        RSRC_CONF|ACCESS_CONF, "Domain rewrite rule for proxying cookies"),
1604     AP_INIT_ITERATE("ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF,
1605      "A list of names, hosts or domains to which the proxy will not connect"),
1606     AP_INIT_TAKE1("ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF,
1607      "Receive buffer size for outgoing HTTP and FTP connections in bytes"),
1608     AP_INIT_TAKE1("ProxyIOBufferSize", set_io_buffer_size, NULL, RSRC_CONF,
1609      "IO buffer size for outgoing HTTP and FTP connections in bytes"),
1610     AP_INIT_TAKE1("ProxyMaxForwards", set_max_forwards, NULL, RSRC_CONF,
1611      "The maximum number of proxies a request may be forwarded through."),
1612     AP_INIT_ITERATE("NoProxy", set_proxy_dirconn, NULL, RSRC_CONF,
1613      "A list of domains, hosts, or subnets to which the proxy will connect directly"),
1614     AP_INIT_TAKE1("ProxyDomain", set_proxy_domain, NULL, RSRC_CONF,
1615      "The default intranet domain name (in absence of a domain in the URL)"),
1616     AP_INIT_ITERATE("AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF,
1617      "A list of ports which CONNECT may connect to"),
1618     AP_INIT_TAKE1("ProxyVia", set_via_opt, NULL, RSRC_CONF,
1619      "Configure Via: proxy header header to one of: on | off | block | full"),
1620     AP_INIT_FLAG("ProxyErrorOverride", set_proxy_error_override, NULL, RSRC_CONF,
1621      "use our error handling pages instead of the servers' we are proxying"),
1622     AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF,
1623      "on if we should preserve host header while proxying"),
1624     AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF,
1625      "Set the timeout (in seconds) for a proxied connection. "
1626      "This overrides the server timeout"),
1627     AP_INIT_TAKE1("ProxyBadHeader", set_bad_opt, NULL, RSRC_CONF,
1628      "How to handle bad header line in response: IsError | Ignore | StartBody"),
1629     AP_INIT_RAW_ARGS("BalancerMember", add_member, NULL, RSRC_CONF|ACCESS_CONF,
1630      "A balancer name and scheme with list of params"), 
1631     AP_INIT_TAKE1("ProxyStatus", set_status_opt, NULL, RSRC_CONF,
1632      "Configure Status: proxy status to one of: on | off | full"),
1633     AP_INIT_RAW_ARGS("ProxySet", set_proxy_param, NULL, RSRC_CONF|ACCESS_CONF,
1634      "A balancer or worker name with list of params"),
1635     {NULL}
1636 };
1637
1638 static APR_OPTIONAL_FN_TYPE(ssl_proxy_enable) *proxy_ssl_enable = NULL;
1639 static APR_OPTIONAL_FN_TYPE(ssl_engine_disable) *proxy_ssl_disable = NULL;
1640
1641 PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c)
1642 {
1643     /* 
1644      * if c == NULL just check if the optional function was imported
1645      * else run the optional function so ssl filters are inserted
1646      */
1647     if (proxy_ssl_enable) {
1648         return c ? proxy_ssl_enable(c) : 1;
1649     }
1650
1651     return 0;
1652 }
1653
1654 PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c)
1655 {
1656     if (proxy_ssl_disable) {
1657         return proxy_ssl_disable(c);
1658     }
1659
1660     return 0;
1661 }
1662
1663 static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,
1664                              apr_pool_t *ptemp, server_rec *s)
1665 {
1666     proxy_server_conf *conf =
1667     (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
1668     proxy_worker *worker;
1669     int i;
1670
1671     proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);
1672     proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
1673
1674     /* Initialize workers */
1675     worker = (proxy_worker *)conf->workers->elts;
1676     for (i = 0; i < conf->workers->nelts; i++) {
1677         ap_proxy_initialize_worker(worker, s);
1678         worker++;
1679     }
1680     /* Initialize forward worker if defined */
1681     if (conf->forward)
1682         ap_proxy_initialize_worker(conf->forward, s);
1683
1684     return OK;
1685 }
1686
1687
1688 #define KBYTE 1024
1689 #define MBYTE 1048576L
1690 #define GBYTE 1073741824L
1691
1692 /* Format the number of bytes nicely */
1693 static void format_byte_out(request_rec *r, apr_off_t bytes)
1694 {
1695
1696     if (bytes < (5 * KBYTE))
1697         ap_rprintf(r, "%d B", (int) bytes);
1698     else if (bytes < (MBYTE / 2))
1699         ap_rprintf(r, "%.1f kB", (float) bytes / KBYTE);
1700     else if (bytes < (GBYTE / 2))
1701         ap_rprintf(r, "%.1f MB", (float) bytes / MBYTE);
1702     else
1703         ap_rprintf(r, "%.1f GB", (float) bytes / GBYTE);
1704 }
1705
1706 /*
1707  *  proxy Extension to mod_status
1708  */
1709 static int proxy_status_hook(request_rec *r, int flags)
1710 {
1711     int i, n;
1712     void *sconf = r->server->module_config;
1713     proxy_server_conf *conf = (proxy_server_conf *)
1714         ap_get_module_config(sconf, &proxy_module);
1715     proxy_balancer *balancer = NULL;
1716     proxy_runtime_worker *worker = NULL;
1717
1718     if (flags & AP_STATUS_SHORT || conf->balancers->nelts == 0 ||
1719         conf->proxy_status == status_off)
1720         return OK;
1721
1722     balancer = (proxy_balancer *)conf->balancers->elts;
1723     for (i = 0; i < conf->balancers->nelts; i++) {
1724         ap_rputs("<hr />\n<h1>Proxy LoadBalancer Status for ", r);
1725         ap_rvputs(r, balancer->name, "</h1>\n\n", NULL);
1726         ap_rputs("\n\n<table border=\"0\"><tr>"
1727                  "<th>SSes</th><th>Timeout</th>"
1728                  "</tr>\n<tr>", r);                
1729         ap_rvputs(r, "<td>", balancer->sticky, NULL);
1730         ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>\n",
1731                    apr_time_sec(balancer->timeout));
1732         ap_rputs("</table>\n", r);
1733         ap_rputs("\n\n<table border=\"0\"><tr>"
1734                  "<th>Sch</th><th>Host</th><th>Stat</th>"
1735                  "<th>Route</th><th>Redir</th>"
1736                  "<th>F</th><th>Acc</th><th>Wr</th><th>Rd</th>"
1737                  "</tr>\n", r);
1738
1739         worker = (proxy_runtime_worker *)balancer->workers->elts;
1740         for (n = 0; n < balancer->workers->nelts; n++) {
1741
1742             ap_rvputs(r, "<tr>\n<td>", worker->w->scheme, "</td>", NULL);
1743             ap_rvputs(r, "<td>", worker->w->hostname, "</td><td>", NULL);
1744             if (worker->w->status & PROXY_WORKER_DISABLED)
1745                 ap_rputs("Dis", r);
1746             else if (worker->w->status & PROXY_WORKER_IN_ERROR)
1747                 ap_rputs("Err", r);
1748             else if (worker->w->status & PROXY_WORKER_INITIALIZED)
1749                 ap_rputs("Ok", r);
1750             else
1751                 ap_rputs("-", r);
1752             ap_rvputs(r, "</td><td>", worker->w->route, NULL);
1753             ap_rvputs(r, "</td><td>", worker->w->redirect, NULL);
1754             ap_rprintf(r, "</td><td>%.2f</td>", worker->s->lbfactor);
1755             ap_rprintf(r, "<td>%d</td><td>", (int)(worker->s->elected));
1756             format_byte_out(r, worker->s->transfered);
1757             ap_rputs("</td><td>", r);
1758             format_byte_out(r, worker->s->transfered);
1759             ap_rputs("</td>\n", r);
1760
1761             /* TODO: Add the rest of dynamic worker data */
1762             ap_rputs("</tr>\n", r);
1763
1764             ++worker;
1765         }
1766         ap_rputs("</table>\n", r);
1767         ++balancer;
1768     }
1769     ap_rputs("<hr /><table>\n"
1770              "<tr><th>SSes</th><td>Sticky session name</td></tr>\n"
1771              "<tr><th>Timeout</th><td>Balancer Timeout</td></tr>\n"
1772              "<tr><th>Sch</th><td>Connection scheme</td></tr>\n"
1773              "<tr><th>Host</th><td>Backend Hostname</td></tr>\n"
1774              "<tr><th>Stat</th><td>Worker status</td></tr>\n"
1775              "<tr><th>Route</th><td>Session Route</td></tr>\n"
1776              "<tr><th>Redir</th><td>Session Route Redirection</td></tr>\n"
1777              "<tr><th>F</th><td>Load Balancer Factor in %</td></tr>\n"
1778              "<tr><th>Acc</th><td>Number of requests</td></tr>\n"
1779              "<tr><th>Wr</th><td>Number of bytes transfered</td></tr>\n"
1780              "<tr><th>Rd</th><td>Number of bytes readed</td></tr>\n"
1781              "</table>", r);
1782
1783     return OK;
1784 }
1785
1786 /*
1787  * This routine is called before the server processes the configuration
1788  * files.  There is no return value.
1789  */
1790 static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
1791                             apr_pool_t *ptemp)
1792 {
1793     APR_OPTIONAL_HOOK(ap, status_hook, proxy_status_hook, NULL, NULL,
1794                       APR_HOOK_MIDDLE);
1795     return OK;
1796 }
1797
1798 static void register_hooks(apr_pool_t *p)
1799 {
1800     /* fixup before mod_rewrite, so that the proxied url will not
1801      * escaped accidentally by our fixup.
1802      */
1803 #ifndef FIX_15207
1804     static const char * const aszSucc[]={ "mod_rewrite.c", NULL };
1805 #endif
1806     
1807     APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_workers);
1808     /* handler */
1809     ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);
1810     /* filename-to-URI translation */
1811     ap_hook_translate_name(proxy_trans, NULL, NULL, APR_HOOK_FIRST);
1812     /* walk <Proxy > entries and suppress default TRACE behavior */
1813     ap_hook_map_to_storage(proxy_map_location, NULL,NULL, APR_HOOK_FIRST);
1814 #ifndef FIX_15207
1815     /* fixups */
1816     ap_hook_fixups(proxy_fixup, NULL, aszSucc, APR_HOOK_FIRST);
1817 #endif
1818     /* post read_request handling */
1819     ap_hook_post_read_request(proxy_detect, NULL, NULL, APR_HOOK_FIRST);
1820     /* pre config handling */
1821     ap_hook_pre_config(proxy_pre_config, NULL, NULL, APR_HOOK_MIDDLE); 
1822     /* post config handling */
1823     ap_hook_post_config(proxy_post_config, NULL, NULL, APR_HOOK_MIDDLE);
1824 }
1825
1826 module AP_MODULE_DECLARE_DATA proxy_module =
1827 {
1828     STANDARD20_MODULE_STUFF,
1829     create_proxy_dir_config,    /* create per-directory config structure */
1830     merge_proxy_dir_config,     /* merge per-directory config structures */
1831     create_proxy_config,        /* create per-server config structure */
1832     merge_proxy_config,         /* merge per-server config structures */
1833     proxy_cmds,                 /* command table */
1834     register_hooks
1835 };
1836
1837 APR_HOOK_STRUCT(
1838     APR_HOOK_LINK(scheme_handler)
1839     APR_HOOK_LINK(canon_handler)
1840     APR_HOOK_LINK(pre_request)
1841     APR_HOOK_LINK(post_request)
1842 )
1843
1844 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler, 
1845                                      (request_rec *r, proxy_worker *worker,
1846                                       proxy_server_conf *conf, 
1847                                       char *url, const char *proxyhost, 
1848                                       apr_port_t proxyport),(r,worker,conf,
1849                                       url,proxyhost,proxyport),DECLINED)
1850 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, canon_handler, 
1851                                       (request_rec *r, char *url),(r,
1852                                       url),DECLINED)
1853 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, pre_request, (
1854                                       proxy_worker **worker,
1855                                       proxy_balancer **balancer,
1856                                       request_rec *r, 
1857                                       proxy_server_conf *conf,
1858                                       char **url),(worker,balancer,
1859                                       r,conf,url),DECLINED)
1860 APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, post_request,
1861                                       (proxy_worker *worker,
1862                                        proxy_balancer *balancer,
1863                                        request_rec *r,
1864                                        proxy_server_conf *conf),(worker,
1865                                        balancer,r,conf),DECLINED)
1866 APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, fixups,
1867                                     (request_rec *r), (r),
1868                                     OK, DECLINED)