]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Applied "canonical reformatting" according to the Apache Style Guide
authorMartin Kraemer <martin@apache.org>
Mon, 25 Mar 2002 09:21:59 +0000 (09:21 +0000)
committerMartin Kraemer <martin@apache.org>
Mon, 25 Mar 2002 09:21:59 +0000 (09:21 +0000)
(indent | pr -t -e8) without changing anything else.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@94158 13f79535-47bb-0310-9956-ffa450edef68

src/modules/proxy/.indent.pro
src/modules/proxy/mod_proxy.c
src/modules/proxy/proxy_cache.c
src/modules/proxy/proxy_connect.c
src/modules/proxy/proxy_ftp.c
src/modules/proxy/proxy_http.c
src/modules/proxy/proxy_util.c

index 20c2d83371def522470977cf664d114a1f75204e..052147d7774e2450ca2bc784f5dee6bcc7d4b09a 100644 (file)
@@ -11,6 +11,7 @@
 -Tbuf_area
 -Tbuff_struct
 -Tbuffy
+-Tcache_req
 -Tcmd_how
 -Tcmd_parms
 -Tcommand_rec
 -Tcore_dir_config
 -Tcore_server_config
 -Tdir_maker_func
+-Tdirconn_entry
 -Tevent
 -Tglobals_s
 -Thandler_func
 -Thandler_rec
+-Tin_addr
 -Tjoblist_s
 -Tlisten_rec
 -Tmerger_func
 -Tmodule_struct
 -Tmutex
 -Tn_long
+-Toff_t
 -Tother_child_rec
 -Toverrides_t
 -Tparent_score
+-Tper_thread_data
 -Tpid_t
 -Tpiped_log
 -Tpool
+-Tproxy_alias
 -Trequest_rec
 -Trequire_line
 -Trlim_t
@@ -46,6 +52,8 @@
 -Tserver_rec
 -Tserver_rec_chain
 -Tshort_score
+-Tsockaddr
+-Tsockaddr_in
 -Ttable
 -Ttable_entry
 -Tthread
index dba6816437975854c04e801fffc5ed848b9b37cf..e9a19315a8fd102be42df8e9837e9c63d317bc80 100644 (file)
@@ -99,8 +99,9 @@ static int alias_match(const char *uri, const char *alias_fakename)
 
     while (aliasp < end_fakename) {
         if (*aliasp == '/') {
-            /* any number of '/' in the alias matches any number in
-             * the supplied URI, but there must be at least one...
+            /*
+             * any number of '/' in the alias matches any number in the
+             * supplied URI, but there must be at least one...
              */
             if (*urip != '/')
                 return 0;
@@ -122,9 +123,9 @@ static int alias_match(const char *uri, const char *alias_fakename)
     if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
         return 0;
 
-    /* Return number of characters from URI which matched (may be
-     * greater than length of alias, since we may have matched
-     * doubled slashes)
+    /*
+     * Return number of characters from URI which matched (may be greater
+     * than length of alias, since we may have matched doubled slashes)
      */
 
     return urip - uri;
@@ -146,14 +147,14 @@ static int proxy_detect(request_rec *r)
     void *sconf = r->server->module_config;
     proxy_server_conf *conf;
 
-    conf = (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
 
     if (conf->req && r->parsed_uri.scheme) {
         /* but it might be something vhosted */
-       if (!(r->parsed_uri.hostname
-            && !strcasecmp(r->parsed_uri.scheme, ap_http_method(r))
-            && ap_matches_request_vhost(r, r->parsed_uri.hostname,
-               r->parsed_uri.port_str ? r->parsed_uri.port : ap_default_port(r)))) {
+        if (!(r->parsed_uri.hostname
+              && !strcasecmp(r->parsed_uri.scheme, ap_http_method(r))
+              && ap_matches_request_vhost(r, r->parsed_uri.hostname,
+        r->parsed_uri.port_str ? r->parsed_uri.port : ap_default_port(r)))) {
             r->proxyreq = STD_PROXY;
             r->uri = r->unparsed_uri;
             r->filename = ap_pstrcat(r->pool, "proxy:", r->uri, NULL);
@@ -164,10 +165,10 @@ static int proxy_detect(request_rec *r)
     else if (conf->req && r->method_number == M_CONNECT
              && r->parsed_uri.hostname
              && r->parsed_uri.port_str) {
-            r->proxyreq = STD_PROXY;
-            r->uri = r->unparsed_uri;
-            r->filename = ap_pstrcat(r->pool, "proxy:", r->uri, NULL);
-            r->handler = "proxy-server";
+        r->proxyreq = STD_PROXY;
+        r->uri = r->unparsed_uri;
+        r->filename = ap_pstrcat(r->pool, "proxy:", r->uri, NULL);
+        r->handler = "proxy-server";
     }
     return DECLINED;
 }
@@ -176,31 +177,33 @@ static int proxy_trans(request_rec *r)
 {
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     int i, len;
-    struct proxy_alias *ent = (struct proxy_alias *) conf->aliases->elts;
+    struct proxy_alias *ent = (struct proxy_alias *)conf->aliases->elts;
 
     if (r->proxyreq != NOT_PROXY) {
-        /* someone has already set up the proxy, it was possibly ourselves
-         * in proxy_detect
+        /*
+         * someone has already set up the proxy, it was possibly ourselves in
+         * proxy_detect
          */
         return OK;
     }
 
-    /* XXX: since r->uri has been manipulated already we're not really
-     * compliant with RFC1945 at this point.  But this probably isn't
-     * an issue because this is a hybrid proxy/origin server.
+    /*
+     * XXX: since r->uri has been manipulated already we're not really
+     * compliant with RFC1945 at this point.  But this probably isn't an
+     * issue because this is a hybrid proxy/origin server.
      */
 
     for (i = 0; i < conf->aliases->nelts; i++) {
         len = alias_match(r->uri, ent[i].fake);
-            
-       if (len > 0) {
-           r->filename = ap_pstrcat(r->pool, "proxy:", ent[i].real,
-                                 r->uri + len, NULL);
-           r->handler = "proxy-server";
-           r->proxyreq = PROXY_PASS;
-           return OK;
+
+        if (len > 0) {
+            r->filename = ap_pstrcat(r->pool, "proxy:", ent[i].real,
+                                     r->uri + len, NULL);
+            r->handler = "proxy-server";
+            r->proxyreq = PROXY_PASS;
+            return OK;
         }
     }
     return DECLINED;
@@ -231,7 +234,7 @@ static int proxy_fixup(request_rec *r)
     if (p == NULL || p == url)
         return HTTP_BAD_REQUEST;
 
-    return OK;          /* otherwise; we've done the best we can */
+    return OK;                  /* otherwise; we've done the best we can */
 }
 
 static void proxy_init(server_rec *r, pool *p)
@@ -258,7 +261,7 @@ static int proxy_needsdomain(request_rec *r, const char *url, const char *domain
 
     /* If host does contain a dot already, or it is "localhost", decline */
     if (strchr(r->parsed_uri.hostname, '.') != NULL
-     || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
+        || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
         return DECLINED;        /* host name has a dot already */
 
     ref = ap_table_get(r->headers_in, "Referer");
@@ -266,17 +269,17 @@ static int proxy_needsdomain(request_rec *r, const char *url, const char *domain
     /* Reassemble the request, but insert the domain after the host name */
     /* Note that the domain name always starts with a dot */
     r->parsed_uri.hostname = ap_pstrcat(r->pool, r->parsed_uri.hostname,
-                                     domain, NULL);
+                                        domain, NULL);
     nuri = ap_unparse_uri_components(r->pool,
-                                  &r->parsed_uri,
-                                  UNP_REVEALPASSWORD);
+                                     &r->parsed_uri,
+                                     UNP_REVEALPASSWORD);
 
     ap_table_set(r->headers_out, "Location", nuri);
-    ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r,
-                "Domain missing: %s sent to %s%s%s", r->uri,
-                ap_unparse_uri_components(r->pool, &r->parsed_uri,
-                      UNP_OMITUSERINFO),
-                ref ? " from " : "", ref ? ref : "");
+    ap_log_rerror(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO, r,
+                  "Domain missing: %s sent to %s%s%s", r->uri,
+                  ap_unparse_uri_components(r->pool, &r->parsed_uri,
+                                            UNP_OMITUSERINFO),
+                  ref ? " from " : "", ref ? ref : "");
 
     return HTTP_MOVED_PERMANENTLY;
 }
@@ -289,7 +292,7 @@ static int proxy_handler(request_rec *r)
     char *url, *scheme, *p;
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     array_header *proxies = conf->proxies;
     struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
     int i, rc;
@@ -312,8 +315,8 @@ static int proxy_handler(request_rec *r)
                 ap_finalize_request_protocol(r);
             return OK;
         }
-        ap_table_setn(r->headers_in, "Max-Forwards", 
-                      ap_psprintf(r->pool, "%ld", (maxfwd > 0) ? maxfwd-1 : 0));
+        ap_table_setn(r->headers_in, "Max-Forwards",
+                ap_psprintf(r->pool, "%ld", (maxfwd > 0) ? maxfwd - 1 : 0));
     }
 
     if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
@@ -343,18 +346,18 @@ static int proxy_handler(request_rec *r)
     /* Check URI's destination host against NoProxy hosts */
     /* Bypass ProxyRemote server lookup if configured as NoProxy */
     /* we only know how to handle communication to a proxy via http */
-    /*if (strcasecmp(scheme, "http") == 0) */
+    /* if (strcasecmp(scheme, "http") == 0) */
     {
         int ii;
-        struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;
+        struct dirconn_entry *list = (struct dirconn_entry *)conf->dirconn->elts;
 
         for (direct_connect = ii = 0; ii < conf->dirconn->nelts && !direct_connect; ii++) {
             direct_connect = list[ii].matcher(&list[ii], r);
         }
 #if DEBUGGING
-        ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r,
-                     (direct_connect) ? "NoProxy for %s" : "UseProxy for %s",
-                     r->uri);
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r,
+                    (direct_connect) ? "NoProxy for %s" : "UseProxy for %s",
+                      r->uri);
 #endif
     }
 
@@ -366,17 +369,18 @@ static int proxy_handler(request_rec *r)
             if (strcmp(ents[i].scheme, "*") == 0 ||
                 (p == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
                 (p != NULL &&
-               strncasecmp(url, ents[i].scheme, strlen(ents[i].scheme)) == 0)) {
-                /* CONNECT is a special method that bypasses the normal
-                 * proxy code.
+            strncasecmp(url, ents[i].scheme, strlen(ents[i].scheme)) == 0)) {
+                /*
+                 * CONNECT is a special method that bypasses the normal proxy
+                 * code.
                  */
                 if (r->method_number == M_CONNECT)
                     rc = ap_proxy_connect_handler(r, cr, url, ents[i].hostname,
-                                               ents[i].port);
+                                                  ents[i].port);
 /* we only know how to handle communication to a proxy via http */
                 else if (strcasecmp(ents[i].protocol, "http") == 0)
                     rc = ap_proxy_http_handler(r, cr, url, ents[i].hostname,
-                                            ents[i].port);
+                                               ents[i].port);
                 else
                     rc = DECLINED;
 
@@ -418,11 +422,12 @@ static void *
     ps->nocaches = ap_make_array(p, 10, sizeof(struct nocache_entry));
     ps->allowed_connect_ports = ap_make_array(p, 10, sizeof(int));
     ps->domain = NULL;
-    ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
-    ps->viaopt_set = 0; /* 0 means default */
+    ps->viaopt = via_off;       /* initially backward compatible with 1.3.1 */
+    ps->viaopt_set = 0;         /* 0 means default */
     ps->req = 0;
     ps->req_set = 0;
-    ps->recv_buffer_size = 0; /* this default was left unset for some reason */
+    ps->recv_buffer_size = 0;   /* this default was left unset for some
+                                 * reason */
     ps->recv_buffer_size_set = 0;
     ps->io_buffer_size = IOBUFSIZE;
     ps->io_buffer_size_set = 0;
@@ -451,11 +456,11 @@ static void *
 
 static void *
      merge_proxy_config(pool *p, void *basev,
-                        void *overridesv)
+                             void *overridesv)
 {
     proxy_server_conf *ps = ap_pcalloc(p, sizeof(proxy_server_conf));
-    proxy_server_conf *base = (proxy_server_conf *) basev;
-    proxy_server_conf *overrides = (proxy_server_conf *) overridesv;
+    proxy_server_conf *base = (proxy_server_conf *)basev;
+    proxy_server_conf *overrides = (proxy_server_conf *)overridesv;
 
     ps->proxies = ap_append_arrays(p, base->proxies, overrides->proxies);
     ps->aliases = ap_append_arrays(p, base->aliases, overrides->aliases);
@@ -490,7 +495,7 @@ static const char *
 {
     server_rec *s = cmd->server;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(s->module_config, &proxy_module);
     struct proxy_remote *new;
     char *p, *q;
     int port;
@@ -508,8 +513,8 @@ static const char *
         port = -1;
     *p = '\0';
     if (strchr(f, ':') == NULL)
-        ap_str_tolower(f);              /* lowercase scheme */
-    ap_str_tolower(p + 3);              /* lowercase hostname */
+        ap_str_tolower(f);      /* lowercase scheme */
+    ap_str_tolower(p + 3);      /* lowercase hostname */
 
     if (port == -1) {
         int i;
@@ -532,7 +537,7 @@ static const char *
 {
     server_rec *s = cmd->server;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(s->module_config, &proxy_module);
     struct proxy_alias *new;
 
     new = ap_push_array(conf->aliases);
@@ -542,14 +547,14 @@ static const char *
 }
 
 static const char *
-    add_pass_reverse(cmd_parms *cmd, void *dummy, char *f, char *r)
+     add_pass_reverse(cmd_parms *cmd, void *dummy, char *f, char *r)
 {
     server_rec *s = cmd->server;
     proxy_server_conf *conf;
     struct proxy_alias *new;
 
-    conf = (proxy_server_conf *)ap_get_module_config(s->module_config, 
-                                                  &proxy_module);
+    conf = (proxy_server_conf *)ap_get_module_config(s->module_config,
+                                                     &proxy_module);
     new = ap_push_array(conf->raliases);
     new->fake = f;
     new->real = r;
@@ -579,7 +584,10 @@ static const char *
         new->name = arg;
         /* Don't do name lookups on things that aren't dotted */
         if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)
-            /*@@@FIXME: This copies only the first of (possibly many) IP addrs */
+            /*
+             * @@@FIXME: This copies only the first of (possibly many) IP
+             * addrs
+             */
             memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
         else
             new->addr.s_addr = 0;
@@ -591,11 +599,11 @@ static const char *
  * Set the ports CONNECT can use
  */
 static const char *
-    set_allowed_ports(cmd_parms *parms, void *dummy, char *arg)
+     set_allowed_ports(cmd_parms *parms, void *dummy, char *arg)
 {
     server_rec *s = parms->server;
     proxy_server_conf *conf =
-      ap_get_module_config(s->module_config, &proxy_module);
+    ap_get_module_config(s->module_config, &proxy_module);
     int *New;
 
     if (!ap_isdigit(arg[0]))
@@ -616,7 +624,7 @@ static const char *
     proxy_server_conf *conf =
     ap_get_module_config(s->module_config, &proxy_module);
     struct dirconn_entry *New;
-    struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;
+    struct dirconn_entry *list = (struct dirconn_entry *)conf->dirconn->elts;
     int found = 0;
     int i;
 
@@ -733,7 +741,7 @@ static const char *
 
     if (sscanf(arg, "%lg", &val) != 1)
         return "CacheMaxExpire value must be a float";
-    psf->cache.maxexpire = (int) (val * (double) SEC_ONE_HR);
+    psf->cache.maxexpire = (int)(val * (double)SEC_ONE_HR);
     psf->cache.maxexpire_set = 1;
     return NULL;
 }
@@ -747,7 +755,7 @@ static const char *
 
     if (sscanf(arg, "%lg", &val) != 1)
         return "CacheDefaultExpire value must be a float";
-    psf->cache.defaultexpire = (int) (val * (double) SEC_ONE_HR);
+    psf->cache.defaultexpire = (int)(val * (double)SEC_ONE_HR);
     psf->cache.defaultexpire_set = 1;
     return NULL;
 }
@@ -761,7 +769,7 @@ static const char *
 
     if (sscanf(arg, "%lg", &val) != 1)
         return "CacheGcInterval value must be a float";
-    psf->cache.gcinterval = (int) (val * (double) SEC_ONE_HR);
+    psf->cache.gcinterval = (int)(val * (double)SEC_ONE_HR);
     psf->cache.gcinterval_set = 1;
     return NULL;
 }
@@ -823,7 +831,10 @@ static const char *
         new->name = arg;
         /* Don't do name lookups on things that aren't dotted */
         if (strchr(arg, '.') != NULL && ap_proxy_host2addr(new->name, &hp) == NULL)
-            /*@@@FIXME: This copies only the first of (possibly many) IP addrs */
+            /*
+             * @@@FIXME: This copies only the first of (possibly many) IP
+             * addrs
+             */
             memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
         else
             new->addr.s_addr = 0;
@@ -858,26 +869,26 @@ static const char *
     return NULL;
 }
 
-static const char*
-    set_cache_completion(cmd_parms *parms, void *dummy, char *arg)
+static const char *
+     set_cache_completion(cmd_parms *parms, void *dummy, char *arg)
 {
     proxy_server_conf *psf =
     ap_get_module_config(parms->server->module_config, &proxy_module);
     int s = atoi(arg);
     if (s > 100 || s < 0) {
         return "CacheForceCompletion must be <= 100 percent, "
-               "or 0 for system default.";
+            "or 0 for system default.";
     }
 
     if (s > 0)
-      psf->cache.cache_completion = ((float)s / 100);
+        psf->cache.cache_completion = ((float)s / 100);
 
     psf->cache.cache_completion_set = 1;
-    return NULL;    
+    return NULL;
 }
 
-static const char*
-    set_via_opt(cmd_parms *parms, void *dummy, char *arg)
+static const char *
+     set_via_opt(cmd_parms *parms, void *dummy, char *arg)
 {
     proxy_server_conf *psf =
     ap_get_module_config(parms->server->module_config, &proxy_module);
@@ -892,11 +903,11 @@ static const char*
         psf->viaopt = via_full;
     else {
         return "ProxyVia must be one of: "
-               "off | on | full | block";
+            "off | on | full | block";
     }
 
     psf->viaopt_set = 1;
-    return NULL;    
+    return NULL;
 }
 
 static const handler_rec proxy_handlers[] =
@@ -908,47 +919,47 @@ static const handler_rec proxy_handlers[] =
 static const command_rec proxy_cmds[] =
 {
     {"ProxyRequests", set_proxy_req, NULL, RSRC_CONF, FLAG,
-     "on if the true proxy requests should be accepted"},
+    "on if the true proxy requests should be accepted"},
     {"ProxyRemote", add_proxy, NULL, RSRC_CONF, TAKE2,
-     "a scheme, partial URL or '*' and a proxy server"},
+    "a scheme, partial URL or '*' and a proxy server"},
     {"ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,
-     "a virtual path and a URL"},
+    "a virtual path and a URL"},
     {"ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF, TAKE2,
-     "a virtual path and a URL for reverse proxy behaviour"},
+    "a virtual path and a URL for reverse proxy behaviour"},
     {"ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE,
-     "A list of names, hosts or domains to which the proxy will not connect"},
+    "A list of names, hosts or domains to which the proxy will not connect"},
     {"ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1,
-     "Receive buffer size for outgoing HTTP and FTP connections in bytes"},
+    "Receive buffer size for outgoing HTTP and FTP connections in bytes"},
     {"ProxyIOBufferSize", set_io_buffer_size, NULL, RSRC_CONF, TAKE1,
-     "IO buffer size for outgoing HTTP and FTP connections in bytes"},
+    "IO buffer size for outgoing HTTP and FTP connections in bytes"},
     {"NoProxy", set_proxy_dirconn, NULL, RSRC_CONF, ITERATE,
-     "A list of domains, hosts, or subnets to which the proxy will connect directly"},
+    "A list of domains, hosts, or subnets to which the proxy will connect directly"},
     {"ProxyDomain", set_proxy_domain, NULL, RSRC_CONF, TAKE1,
-     "The default intranet domain name (in absence of a domain in the URL)"},
+    "The default intranet domain name (in absence of a domain in the URL)"},
     {"AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF, ITERATE,
-     "A list of ports which CONNECT may connect to"},
+    "A list of ports which CONNECT may connect to"},
     {"CacheRoot", set_cache_root, NULL, RSRC_CONF, TAKE1,
-     "The directory to store cache files"},
+    "The directory to store cache files"},
     {"CacheSize", set_cache_size, NULL, RSRC_CONF, TAKE1,
-     "The maximum disk space used by the cache in Kb"},
+    "The maximum disk space used by the cache in Kb"},
     {"CacheMaxExpire", set_cache_maxex, NULL, RSRC_CONF, TAKE1,
-     "The maximum time in hours to cache a document"},
+    "The maximum time in hours to cache a document"},
     {"CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF, TAKE1,
-     "The default time in hours to cache a document"},
+    "The default time in hours to cache a document"},
     {"CacheLastModifiedFactor", set_cache_factor, NULL, RSRC_CONF, TAKE1,
-     "The factor used to estimate Expires date from LastModified date"},
+    "The factor used to estimate Expires date from LastModified date"},
     {"CacheGcInterval", set_cache_gcint, NULL, RSRC_CONF, TAKE1,
-     "The interval between garbage collections, in hours"},
+    "The interval between garbage collections, in hours"},
     {"CacheDirLevels", set_cache_dirlevels, NULL, RSRC_CONF, TAKE1,
-     "The number of levels of subdirectories in the cache"},
+    "The number of levels of subdirectories in the cache"},
     {"CacheDirLength", set_cache_dirlength, NULL, RSRC_CONF, TAKE1,
-     "The number of characters in subdirectory names"},
+    "The number of characters in subdirectory names"},
     {"NoCache", set_cache_exclude, NULL, RSRC_CONF, ITERATE,
-     "A list of names, hosts or domains for which caching is *not* provided"},
+    "A list of names, hosts or domains for which caching is *not* provided"},
     {"CacheForceCompletion", set_cache_completion, NULL, RSRC_CONF, TAKE1,
-     "Force a http cache completion after this percentage is loaded"},
+    "Force a http cache completion after this percentage is loaded"},
     {"ProxyVia", set_via_opt, NULL, RSRC_CONF, TAKE1,
-     "Configure Via: proxy header header to one of: on | off | block | full"},
+    "Configure Via: proxy header header to one of: on | off | block | full"},
     {NULL}
 };
 
@@ -974,5 +985,3 @@ module MODULE_VAR_EXPORT proxy_module =
     NULL,                       /* child_exit */
     proxy_detect                /* post read-request */
 };
-
-
index 41d619e6b23c415fa801a06680cb7c5c9fe52fd6..73c2d733231ba5f7cbf28748e7ce91dee8b9af45 100644 (file)
@@ -68,7 +68,7 @@
 #include <sys/utime.h>
 #else
 #include <utime.h>
-#endif /* WIN32 */
+#endif                          /* WIN32 */
 #include "multithread.h"
 #include "ap_md5.h"
 #ifdef __TANDEM
@@ -87,9 +87,9 @@ struct gc_ent {
 
 /* Poor man's 61 bit arithmetic */
 typedef struct {
-    long lower; /* lower 30 bits of result */
-    long upper; /* upper 31 bits of result */
-} long61_t;
+    long lower;                 /* lower 30 bits of result */
+    long upper;                 /* upper 31 bits of result */
+}      long61_t;
 
 /* FIXME: The block size can be different on a `per file system' base.
  * This would make automatic detection highly OS specific.
@@ -123,7 +123,7 @@ int ap_proxy_garbage_init(server_rec *r, pool *p)
 
 
 static int sub_garbage_coll(request_rec *r, array_header *files,
-                            const char *cachedir, const char *cachesubdir);
+                             const char *cachedir, const char *cachesubdir);
 static void help_proxy_garbage_coll(request_rec *r);
 static int should_proxy_garbage_coll(request_rec *r);
 #if !defined(WIN32) && !defined(MPE) && !defined(OS2) && !defined(NETWARE) && !defined(TPF)
@@ -135,14 +135,14 @@ void ap_proxy_garbage_coll(request_rec *r)
 {
     static int inside = 0;
 
-    (void) ap_acquire_mutex(garbage_mutex);
+    (void)ap_acquire_mutex(garbage_mutex);
     if (inside == 1) {
-        (void) ap_release_mutex(garbage_mutex);
+        (void)ap_release_mutex(garbage_mutex);
         return;
     }
     else
         inside = 1;
-    (void) ap_release_mutex(garbage_mutex);
+    (void)ap_release_mutex(garbage_mutex);
 
     ap_block_alarms();          /* avoid SIGALRM on big cache cleanup */
     if (should_proxy_garbage_coll(r))
@@ -153,14 +153,13 @@ void ap_proxy_garbage_coll(request_rec *r)
 #endif
     ap_unblock_alarms();
 
-    (void) ap_acquire_mutex(garbage_mutex);
+    (void)ap_acquire_mutex(garbage_mutex);
     inside = 0;
-    (void) ap_release_mutex(garbage_mutex);
+    (void)ap_release_mutex(garbage_mutex);
 }
 
 
-static void
-add_long61 (long61_t *accu, long val)
+static void add_long61(long61_t * accu, long val)
 {
     /* Add in lower 30 bits */
     accu->lower += (val & 0x3FFFFFFFL);
@@ -170,8 +169,7 @@ add_long61 (long61_t *accu, long val)
     accu->lower &= 0x3FFFFFFFL;
 }
 
-static void
-sub_long61 (long61_t *accu, long val)
+static void sub_long61(long61_t * accu, long val)
 {
     int carry = (val & 0x3FFFFFFFL) > accu->lower;
     /* Subtract lower 30 bits */
@@ -185,11 +183,10 @@ sub_long61 (long61_t *accu, long val)
  * return  0 when left == right
  * return >0 when left > right
  */
-static long
-cmp_long61 (long61_t *left, long61_t *right)
+static long cmp_long61(long61_t * left, long61_t * right)
 {
     return (left->upper == right->upper) ? (left->lower - right->lower)
-                                         : (left->upper - right->upper);
+    : (left->upper - right->upper);
 }
 
 /* Compare two gc_ent's, sort them by expiration date */
@@ -215,66 +212,66 @@ static void detached_proxy_garbage_coll(request_rec *r)
 
 #if 0
     ap_log_error(APLOG_MARK, APLOG_DEBUG, r->server,
-                         "proxy: Guess what; we fork() again...");
+                 "proxy: Guess what; we fork() again...");
 #endif
     switch (pid = fork()) {
-        case -1:
-            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                         "proxy: fork() for cache cleanup failed");
-            return;
+    case -1:
+        ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                     "proxy: fork() for cache cleanup failed");
+        return;
 
-        case 0: /* Child */
+    case 0:                     /* Child */
 
-            /* close all sorts of things, including the socket fd */
-            ap_cleanup_for_exec();
+        /* close all sorts of things, including the socket fd */
+        ap_cleanup_for_exec();
 
-            /* Fork twice to disassociate from the child */
-            switch (pid = fork()) {
-                case -1:
-                    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+        /* Fork twice to disassociate from the child */
+        switch (pid = fork()) {
+        case -1:
+            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                          "proxy: fork(2nd) for cache cleanup failed");
-                    exit(1);
+            exit(1);
 
-                case 0: /* Child */
-                    /* The setpgrp() stuff was snarfed from http_main.c */
+        case 0:         /* Child */
+            /* The setpgrp() stuff was snarfed from http_main.c */
 #ifndef NO_SETSID
-                    if ((pgrp = setsid()) == -1) {
-                        perror("setsid");
-                        fprintf(stderr, "%s: setsid failed\n",
-                                ap_server_argv0);
-                        exit(1);
-                    }
+            if ((pgrp = setsid()) == -1) {
+                perror("setsid");
+                fprintf(stderr, "%s: setsid failed\n",
+                        ap_server_argv0);
+                exit(1);
+            }
 #elif defined(NEXT) || defined(NEWSOS)
-                    if (setpgrp(0, getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
-                        perror("setpgrp");
-                        fprintf(stderr, "%S: setpgrp or getpgrp failed\n",
-                                ap_server_argv0);
-                        exit(1);
-                    }
+            if (setpgrp(0, getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
+                perror("setpgrp");
+                fprintf(stderr, "%S: setpgrp or getpgrp failed\n",
+                        ap_server_argv0);
+                exit(1);
+            }
 #else
-                    if ((pgrp = setpgrp(getpid(), 0)) == -1) {
-                        perror("setpgrp");
-                        fprintf(stderr, "%s: setpgrp failed\n",
-                                ap_server_argv0);
-                        exit(1);
-                    }
+            if ((pgrp = setpgrp(getpid(), 0)) == -1) {
+                perror("setpgrp");
+                fprintf(stderr, "%s: setpgrp failed\n",
+                        ap_server_argv0);
+                exit(1);
+            }
 #endif
-                    help_proxy_garbage_coll(r);
-                    exit(0);
+            help_proxy_garbage_coll(r);
+            exit(0);
 
-                default:    /* Father */
-                    /* After grandson has been forked off, */
-                    /* there's nothing else to do. */
-                    exit(0);
-            }
-        default:
-            /* Wait until grandson has been forked off */
-            /* (without wait we'd leave a zombie) */
-            waitpid(pid, &status, 0);
-            return;
+        default:                /* Father */
+            /* After grandson has been forked off, */
+            /* there's nothing else to do. */
+            exit(0);
+        }
+    default:
+        /* Wait until grandson has been forked off */
+        /* (without wait we'd leave a zombie) */
+        waitpid(pid, &status, 0);
+        return;
     }
 }
-#endif /* ndef WIN32 */
+#endif                          /* ndef WIN32 */
 
 #define DOT_TIME "/.time"       /* marker */
 
@@ -282,7 +279,7 @@ static int should_proxy_garbage_coll(request_rec *r)
 {
     void *sconf = r->server->module_config;
     proxy_server_conf *pconf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     const struct cache_conf *conf = &pconf->cache;
 
     const char *cachedir = conf->root;
@@ -290,34 +287,36 @@ static int should_proxy_garbage_coll(request_rec *r)
     struct stat buf;
     int timefd;
     time_t every = conf->gcinterval;
-    static time_t lastcheck = BAD_DATE;         /* static (per-process) data!!! */
+    static time_t lastcheck = BAD_DATE; /* static (per-process) data!!! */
 
     if (cachedir == NULL || every == -1)
         return 0;
 
-    filename = ap_palloc(r->pool, strlen(cachedir) + strlen( DOT_TIME ) +1);
+    filename = ap_palloc(r->pool, strlen(cachedir) + strlen(DOT_TIME) + 1);
 
     garbage_now = time(NULL);
-    /* Usually, the modification time of <cachedir>/.time can only increase.
+    /*
+     * Usually, the modification time of <cachedir>/.time can only increase.
      * Thus, even with several child processes having their own copy of
-     * lastcheck, if time(NULL) still < lastcheck then it's not time
-     * for GC yet.
+     * lastcheck, if time(NULL) still < lastcheck then it's not time for GC
+     * yet.
      */
     if (garbage_now != -1 && lastcheck != BAD_DATE && garbage_now < lastcheck + every)
         return 0;
 
-    strcpy(filename,cachedir);
-    strcat(filename,DOT_TIME);
+    strcpy(filename, cachedir);
+    strcat(filename, DOT_TIME);
 
-    /* At this point we have a bit of an engineering compromise. We could either
-     * create and/or mark the .time file  (prior to the fork which might
-     * fail on a resource issue) or wait until we are safely forked. The
-     * advantage of doing it now in this process is that we get some
-     * usefull live out of the global last check variable. (XXX which
-     * should go scoreboard IMHO.) Note that the actual counting is 
-     * at a later moment.
+    /*
+     * At this point we have a bit of an engineering compromise. We could
+     * either create and/or mark the .time file  (prior to the fork which
+     * might fail on a resource issue) or wait until we are safely forked.
+     * The advantage of doing it now in this process is that we get some
+     * usefull live out of the global last check variable. (XXX which should
+     * go scoreboard IMHO.) Note that the actual counting is at a later
+     * moment.
      */
-   if (stat(filename, &buf) == -1) {   /* does not exist */
+    if (stat(filename, &buf) == -1) {   /* does not exist */
         if (errno != ENOENT) {
             ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
                          "proxy: stat(%s)", filename);
@@ -351,7 +350,7 @@ static void help_proxy_garbage_coll(request_rec *r)
     const char *cachedir;
     void *sconf = r->server->module_config;
     proxy_server_conf *pconf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     const struct cache_conf *conf = &pconf->cache;
     array_header *files;
     struct gc_ent *fent;
@@ -372,9 +371,9 @@ static void help_proxy_garbage_coll(request_rec *r)
     sub_garbage_coll(r, files, cachedir, "/");
 
     if (cmp_long61(&curbytes, &cachesize) < 0L) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-                         "proxy GC: Cache is %ld%% full (nothing deleted)",
-                         (long)(((curbytes.upper<<20)|(curbytes.lower>>10))*100/conf->space));
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "proxy GC: Cache is %ld%% full (nothing deleted)",
+                     (long)(((curbytes.upper << 20) | (curbytes.lower >> 10)) * 100 / conf->space));
         ap_unblock_alarms();
         return;
     }
@@ -385,7 +384,7 @@ static void help_proxy_garbage_coll(request_rec *r)
     for (i = 0; i < files->nelts; i++) {
         fent = &((struct gc_ent *) files->elts)[i];
         sprintf(filename, "%s%s", cachedir, fent->file);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "GC Unlinking %s (expiry %ld, garbage_now %ld)", filename, (long)fent->expire, (long)garbage_now);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "GC Unlinking %s (expiry %ld, garbage_now %ld)", filename, (long)fent->expire, (long)garbage_now);
 #if TESTING
         fprintf(stderr, "Would unlink %s\n", filename);
 #else
@@ -403,16 +402,16 @@ static void help_proxy_garbage_coll(request_rec *r)
         }
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-                         "proxy GC: Cache is %ld%% full (%d deleted)",
-                         (long)(((curbytes.upper<<20)|(curbytes.lower>>10))*100/conf->space), i);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                 "proxy GC: Cache is %ld%% full (%d deleted)",
+                 (long)(((curbytes.upper << 20) | (curbytes.lower >> 10)) * 100 / conf->space), i);
     ap_unblock_alarms();
 }
 
 static int sub_garbage_coll(request_rec *r, array_header *files,
                           const char *cachebasedir, const char *cachesubdir)
 {
-    char line[17*(3)];
+    char line[17 * (3)];
     char cachedir[HUGE_STRING_LEN];
     struct stat buf;
     int fd, i;
@@ -428,7 +427,7 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
 
     ap_snprintf(cachedir, sizeof(cachedir), "%s%s", cachebasedir, cachesubdir);
     filename = ap_palloc(r->pool, strlen(cachedir) + HASH_LEN + 2);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "GC Examining directory %s", cachedir);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "GC Examining directory %s", cachedir);
     dir = opendir(cachedir);
     if (dir == NULL) {
         ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
@@ -440,7 +439,7 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
         if (ent->d_name[0] == '.')
             continue;
         sprintf(filename, "%s%s", cachedir, ent->d_name);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "GC Examining file %s", filename);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "GC Examining file %s", filename);
 /* is it a temporary file? */
         if (strncmp(ent->d_name, "tmp", 3) == 0) {
 /* then stat it to see how old it is; delete temporary files > 1 day old */
@@ -451,9 +450,9 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
             }
             else if (garbage_now != -1 && buf.st_atime < garbage_now - SEC_ONE_DAY &&
                      buf.st_mtime < garbage_now - SEC_ONE_DAY) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "GC unlink %s", filename);
-                ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r->server,
-                             "proxy gc: deleting orphaned cache file %s", filename);
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "GC unlink %s", filename);
+                ap_log_error(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO, r->server,
+                     "proxy gc: deleting orphaned cache file %s", filename);
 #if TESTING
                 fprintf(stderr, "Would unlink %s\n", filename);
 #else
@@ -465,7 +464,7 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
         ++nfiles;
 /* is it another file? */
         /* FIXME: Shouldn't any unexpected files be deleted? */
-        /*      if (strlen(ent->d_name) != HASH_LEN) continue; */
+        /* if (strlen(ent->d_name) != HASH_LEN) continue; */
 
 /* under OS/2 use dirent's d_attr to identify a diretory */
 /* under TPF use stat to identify a directory */
@@ -474,122 +473,124 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
 #ifdef OS2
         if (ent->d_attr & A_DIR) {
 #elif defined(TPF)
-    if (stat(filename, &buf) == -1) {
-        if (errno != ENOENT)
-            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                 "proxy gc: stat(%s)", filename);
-    }
-    if (S_ISDIR(buf.st_mode)) {
+            if (stat(filename, &buf) == -1) {
+                if (errno != ENOENT)
+                    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                                 "proxy gc: stat(%s)", filename);
+            }
+            if (S_ISDIR(buf.st_mode)) {
 #endif
-            char newcachedir[HUGE_STRING_LEN];
-            ap_snprintf(newcachedir, sizeof(newcachedir),
-                        "%s%s/", cachesubdir, ent->d_name);
-            if (!sub_garbage_coll(r, files, cachebasedir, newcachedir)) {
+                char newcachedir[HUGE_STRING_LEN];
                 ap_snprintf(newcachedir, sizeof(newcachedir),
-                            "%s%s", cachedir, ent->d_name);
+                            "%s%s/", cachesubdir, ent->d_name);
+                if (!sub_garbage_coll(r, files, cachebasedir, newcachedir)) {
+                    ap_snprintf(newcachedir, sizeof(newcachedir),
+                                "%s%s", cachedir, ent->d_name);
 #if TESTING
-                fprintf(stderr, "Would remove directory %s\n", newcachedir);
+                    fprintf(stderr, "Would remove directory %s\n", newcachedir);
 #else
-                rmdir(newcachedir);
+                    rmdir(newcachedir);
 #endif
-                --nfiles;
+                    --nfiles;
+                }
+                continue;
             }
-            continue;
-        }
 #endif
 
 /* read the file */
 #if defined(WIN32)
-        /* On WIN32 open does not work for directories, 
-         * so we us stat instead of fstat to determine 
-         * if the file is a directory 
-         */
-        if (stat(filename, &buf) == -1) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                         "proxy gc: stat(%s)", filename);
-            continue;
-        }
-        fd = -1;
+            /*
+             * On WIN32 open does not work for directories, so we us stat
+             * instead of fstat to determine if the file is a directory
+             */
+            if (stat(filename, &buf) == -1) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                             "proxy gc: stat(%s)", filename);
+                continue;
+            }
+            fd = -1;
 #else
-        fd = open(filename, O_RDONLY | O_BINARY);
-        if (fd == -1) {
-            if (errno != ENOENT)
+            fd = open(filename, O_RDONLY | O_BINARY);
+            if (fd == -1) {
+                if (errno != ENOENT)
+                    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                                 "proxy gc: open(%s)", filename);
+                continue;
+            }
+            if (fstat(fd, &buf) == -1) {
                 ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                             "proxy gc: open(%s)", filename);
-            continue;
-        }
-        if (fstat(fd, &buf) == -1) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                         "proxy gc: fstat(%s)", filename);
-            close(fd);
-            continue;
-        }
+                             "proxy gc: fstat(%s)", filename);
+                close(fd);
+                continue;
+            }
 #endif
 
 /* In OS/2 and TPF this has already been done above */
 #if !defined(OS2) && !defined(TPF)
-        if (S_ISDIR(buf.st_mode)) {
-            char newcachedir[HUGE_STRING_LEN];
+            if (S_ISDIR(buf.st_mode)) {
+                char newcachedir[HUGE_STRING_LEN];
 #if !defined(WIN32)
-            /* Win32 used stat, no file to close */
-            close(fd);
+                /* Win32 used stat, no file to close */
+                close(fd);
 #endif
-            ap_snprintf(newcachedir, sizeof(newcachedir),
-                        "%s%s/", cachesubdir, ent->d_name);
-            if (!sub_garbage_coll(r, files, cachebasedir, newcachedir)) {
                 ap_snprintf(newcachedir, sizeof(newcachedir),
-                            "%s%s", cachedir, ent->d_name);
+                            "%s%s/", cachesubdir, ent->d_name);
+                if (!sub_garbage_coll(r, files, cachebasedir, newcachedir)) {
+                    ap_snprintf(newcachedir, sizeof(newcachedir),
+                                "%s%s", cachedir, ent->d_name);
 #if TESTING
-                fprintf(stderr, "Would remove directory %s\n", newcachedir);
+                    fprintf(stderr, "Would remove directory %s\n", newcachedir);
 #else
-                rmdir(newcachedir);
+                    rmdir(newcachedir);
 #endif
-                --nfiles;
-            } else {
-                /* Directory is not empty. Account for its size: */
-                add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
+                    --nfiles;
+                }
+                else {
+                    /* Directory is not empty. Account for its size: */
+                    add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
+                }
+                continue;
             }
-            continue;
-        }
 #endif
 
 #if defined(WIN32)
-        /* Since we have determined above that the file is not a directory,
-         * it should be safe to open it now 
-         */
-        fd = open(filename, O_RDONLY | O_BINARY);
-        if (fd == -1) {
-            if (errno != ENOENT)
-                ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                             "proxy gc: open(%s) = %d", filename, errno);
-            continue;
-        }
+            /*
+             * Since we have determined above that the file is not a
+             * directory, it should be safe to open it now
+             */
+            fd = open(filename, O_RDONLY | O_BINARY);
+            if (fd == -1) {
+                if (errno != ENOENT)
+                    ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                                 "proxy gc: open(%s) = %d", filename, errno);
+                continue;
+            }
 #endif
-        i = read(fd, line, 17*(3)-1);
-        close(fd);
-        if (i == -1) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
-                         "proxy gc: read(%s)", filename);
-            continue;
-        }
-        line[i] = '\0';
-        garbage_expire = ap_proxy_hex2sec(line + 17*(2));
-        if (!ap_checkmask(line, "&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&") ||
-            garbage_expire == BAD_DATE) {
-            /* bad file */
-            if (garbage_now != -1 && buf.st_atime > garbage_now + SEC_ONE_DAY &&
-                buf.st_mtime > garbage_now + SEC_ONE_DAY) {
-                ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, r->server,
-                             "proxy: deleting bad cache file with future date: %s", filename);
+
+            i = read(fd, line, 17 * (3) - 1);
+            close(fd);
+            if (i == -1) {
+                ap_log_error(APLOG_MARK, APLOG_ERR, r->server,
+                             "proxy gc: read(%s)", filename);
+                continue;
+            }
+            line[i] = '\0';
+            garbage_expire = ap_proxy_hex2sec(line + 17 * (2));
+            if (!ap_checkmask(line, "&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&") ||
+                garbage_expire == BAD_DATE) {
+                /* bad file */
+                if (garbage_now != -1 && buf.st_atime > garbage_now + SEC_ONE_DAY &&
+                    buf.st_mtime > garbage_now + SEC_ONE_DAY) {
+                    ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, r->server,
+                                 "proxy: deleting bad cache file with future date: %s", filename);
 #if TESTING
-                fprintf(stderr, "Would unlink bad file %s\n", filename);
+                    fprintf(stderr, "Would unlink bad file %s\n", filename);
 #else
-                unlink(filename);
+                    unlink(filename);
 #endif
+                }
+                continue;
             }
-            continue;
-        }
 
 /*
  * we need to calculate an 'old' factor, and remove the 'oldest' files
@@ -597,21 +598,21 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
  * file.
  *
  */
-        fent = (struct gc_ent *) ap_push_array(files);
-        fent->len = buf.st_size;
-        fent->expire = garbage_expire;
-        strcpy(fent->file, cachesubdir);
-        strcat(fent->file, ent->d_name);
+            fent = (struct gc_ent *) ap_push_array(files);
+            fent->len = buf.st_size;
+            fent->expire = garbage_expire;
+            strcpy(fent->file, cachesubdir);
+            strcat(fent->file, ent->d_name);
 
 /* accumulate in blocks, to cope with directories > 4Gb */
-        add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
-    }
+            add_long61(&curbytes, ROUNDUP2BLOCKS(buf.st_size));
+        }
 
-    closedir(dir);
+        closedir(dir);
 
-    return nfiles;
+        return nfiles;
 
-}
+    }
 
 
 /*
@@ -625,94 +626,89 @@ static int sub_garbage_coll(request_rec *r, array_header *files,
  * pointing at the start of the message body itself, ready to be
  * shipped to the client later on, if appropriate.
  */
-static int rdcache(request_rec *r, BUFF *cachefp, cache_req *c)
-{
-    char urlbuff[HUGE_STRING_LEN], *strp;
-    int len;
-
-    /* read the data from the cache file */
-
-    /* Format:
-     *
-     * The cache needs to keep track of the following information:
-     * - Date, LastMod, Version, ReqTime, RespTime, ContentLength
-     * - The original request headers (for Vary)
-     * - The original response headers (for returning with a cached response)
-     * - The body of the message
-     *
-     * date SP lastmod SP expire SP count SP request-time SP response-time SP content-lengthCRLF
-     * (dates are stored as hex seconds since 1970)
-     * Original URLCRLF
-     * Original Request Headers
-     * CRLF
-     * Original Response Headers
-     * CRLF
-     * Body
-     * 
-     */
-
-    /* retrieve cachefile information values */
-    len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
-    if (len == -1)
-        return -1;
-    if (len == 0 || urlbuff[len - 1] != '\n')
-        return 0;
-    urlbuff[len - 1] = '\0';
-
-    if (!ap_checkmask(urlbuff,
-                   "&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&"))
-        return 0;
-
-    c->date = ap_proxy_hex2sec(urlbuff + 17*(0));
-    c->lmod = ap_proxy_hex2sec(urlbuff + 17*(1));
-    c->expire = ap_proxy_hex2sec(urlbuff + 17*(2));
-    c->version = ap_proxy_hex2sec(urlbuff + 17*(3));
-    c->req_time = ap_proxy_hex2sec(urlbuff + 17*(4));
-    c->resp_time = ap_proxy_hex2sec(urlbuff + 17*(5));
-    c->len = ap_proxy_hex2sec(urlbuff + 17*(6));
-
-    /* check that we have the same URL */
-    len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
-    if (len == -1)
-        return -1;
-    if (len == 0 || strncmp(urlbuff, "X-URL: ", 7) != 0 ||
-        urlbuff[len - 1] != '\n')
-        return 0;
-    urlbuff[len - 1] = '\0';
-    if (strcmp(urlbuff + 7, c->url) != 0)
-        return 0;
-
-    /* then the original request headers */
-    c->req_hdrs = ap_proxy_read_headers(r, urlbuff, sizeof urlbuff, cachefp);
-    if (c->req_hdrs == NULL)
-        return -1;
-
-    /* then the original response headers */
-    len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
-    if (len == -1)
-        return -1;
-    if (len == 0 || urlbuff[len - 1] != '\n')
-        return 0;
-    urlbuff[--len] = '\0';
+    static int rdcache(request_rec *r, BUFF *cachefp, cache_req *c){
+        char urlbuff[HUGE_STRING_LEN], *strp;
+        int len;
+
+        /* read the data from the cache file */
+
+        /*
+         * Format:
+         * 
+         * The cache needs to keep track of the following information: - Date,
+         * LastMod, Version, ReqTime, RespTime, ContentLength - The original
+         * request headers (for Vary) - The original response headers (for
+         * returning with a cached response) - The body of the message
+         * 
+         * date SP lastmod SP expire SP count SP request-time SP response-time
+         * SP content-lengthCRLF (dates are stored as hex seconds since 1970)
+         * Original URLCRLF Original Request Headers CRLF Original Response
+         * Headers CRLF Body
+         * 
+         */
 
-    c->resp_line = ap_pstrdup(r->pool, urlbuff);
-    strp = strchr(urlbuff, ' ');
-    if (strp == NULL)
-        return 0;
+        /* retrieve cachefile information values */
+            len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
+        if  (len == -1)
+                return -1;
+        if  (len == 0 || urlbuff[len - 1] != '\n')
+                return 0;
+            urlbuff[len - 1] = '\0';
+
+        if  (!ap_checkmask(urlbuff,
+                               "&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&"))
+                return 0;
+
+            c->date = ap_proxy_hex2sec(urlbuff + 17 * (0));
+            c->lmod = ap_proxy_hex2sec(urlbuff + 17 * (1));
+            c->expire = ap_proxy_hex2sec(urlbuff + 17 * (2));
+            c->version = ap_proxy_hex2sec(urlbuff + 17 * (3));
+            c->req_time = ap_proxy_hex2sec(urlbuff + 17 * (4));
+            c->resp_time = ap_proxy_hex2sec(urlbuff + 17 * (5));
+            c->len = ap_proxy_hex2sec(urlbuff + 17 * (6));
+
+        /* check that we have the same URL */
+            len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
+        if  (len == -1)
+                return -1;
+        if  (len == 0 || strncmp(urlbuff, "X-URL: ", 7) != 0 ||
+                 urlbuff[len - 1] != '\n')
+                return 0;
+            urlbuff[len - 1] = '\0';
+        if  (strcmp(urlbuff + 7, c->url) != 0)
+                return 0;
+
+        /* then the original request headers */
+            c->req_hdrs = ap_proxy_read_headers(r, urlbuff, sizeof urlbuff, cachefp);
+        if  (c->req_hdrs == NULL)
+                return -1;
+
+        /* then the original response headers */
+            len = ap_bgets(urlbuff, sizeof urlbuff, cachefp);
+        if  (len == -1)
+                return -1;
+        if  (len == 0 || urlbuff[len - 1] != '\n')
+                return 0;
+            urlbuff[--len] = '\0';
+
+            c->resp_line = ap_pstrdup(r->pool, urlbuff);
+            strp = strchr(urlbuff, ' ');
+        if  (strp == NULL)
+                return 0;
+
+            c->status = atoi(strp);
+            c->hdrs = ap_proxy_read_headers(r, urlbuff, sizeof urlbuff, cachefp);
+        if  (c->hdrs == NULL)
+                return -1;
+        if  (c->len != -1)      /* add a content-length header */
+            if  (ap_table_get(c->hdrs, "Content-Length") == NULL) {
+                ap_table_set(c->hdrs, "Content-Length",
+                        ap_psprintf(r->pool, "%lu", (unsigned long)c->len));
+            }
 
-    c->status = atoi(strp);
-    c->hdrs = ap_proxy_read_headers(r, urlbuff, sizeof urlbuff, cachefp);
-    if (c->hdrs == NULL)
-        return -1;
-    if (c->len != -1)    /* add a content-length header */
-        if (ap_table_get(c->hdrs, "Content-Length") == NULL) {
-            ap_table_set(c->hdrs, "Content-Length",
-                         ap_psprintf(r->pool, "%lu", (unsigned long)c->len));
-        }
 
-    
-    return 1;
-}
+            return 1;
+    }
 
 /*
  * Call this to check the possible conditional status of
@@ -723,190 +719,191 @@ static int rdcache(request_rec *r, BUFF *cachefp, cache_req *c)
  *
  * We don't yet understand If-Range, but we will...
  */
-int ap_proxy_cache_conditional(request_rec *r, cache_req *c, BUFF *cachefp)
-{
-    const char *etag, *wetag = NULL;
+    int ap_proxy_cache_conditional(request_rec *r, cache_req *c, BUFF *cachefp){
+        const char *etag, *wetag = NULL;
 
-    /* get etag */
-    if ((etag = ap_table_get(c->hdrs, "Etag"))) {
-        wetag = ap_pstrcat(r->pool, "W/", etag, NULL);
-    }
-
-    /* check for If-Match, If-Unmodified-Since */
-    while (1) {
-
-        /* check If-Match and If-Unmodified-Since exist
-         *
-         * If neither of these exist, the request is not conditional, and
-         * we serve it normally
-         */
-        if (!c->im && BAD_DATE == c->ius) {
-            break;
+        /* get etag */
+        if   ((etag = ap_table_get(c->hdrs, "Etag"))) {
+            wetag = ap_pstrcat(r->pool, "W/", etag, NULL);
         }
 
-        /* check If-Match
-         *
-         * we check if the Etag on the cached file is in the list of Etags
-         * in the If-Match field. The comparison must be a strong comparison,
-         * so the Etag cannot be marked as weak. If the comparision fails
-         * we return 412 Precondition Failed.
-         *
-         * if If-Match is specified AND
-         * If-Match is not a "*" AND
-         * Etag is missing or weak or not in the list THEN
-         * return 412 Precondition Failed
-         */
+        /* check for If-Match, If-Unmodified-Since */
+        while (1) {
 
-        if (c->im) {
-            if (strcmp(c->im, "*") &&
-            (!etag || (strlen(etag) > 1 && 'W' == etag[0] && '/' == etag[1]) || !ap_proxy_liststr(c->im, etag, NULL))) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-Match specified, and it didn't - return 412");
-            }
-            else {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-Match specified, and it matched");
+            /*
+             * check If-Match and If-Unmodified-Since exist
+             * 
+             * If neither of these exist, the request is not conditional, and we
+             * serve it normally
+             */
+            if (!c->im && BAD_DATE == c->ius) {
                 break;
             }
-        }
 
-        /* check If-Unmodified-Since
-         *
-         * if If-Unmodified-Since is specified AND
-         * Last-Modified is specified somewhere AND
-         * If-Unmodified-Since is in the past compared to Last-Modified THEN
-         * return 412 Precondition Failed
-         */
-        if (BAD_DATE != c->ius && BAD_DATE != c->lmod) {
-            if (c->ius < c->lmod) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-Unmodified-Since specified, but it wasn't - return 412");
-            }
-            else {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-Unmodified-Since specified, and it was unmodified");
-                break;
+            /*
+             * check If-Match
+             * 
+             * we check if the Etag on the cached file is in the list of Etags
+             * in the If-Match field. The comparison must be a strong
+             * comparison, so the Etag cannot be marked as weak. If the
+             * comparision fails we return 412 Precondition Failed.
+             * 
+             * if If-Match is specified AND If-Match is not a "*" AND Etag is
+             * missing or weak or not in the list THEN return 412
+             * Precondition Failed
+             */
+
+            if (c->im) {
+                if (strcmp(c->im, "*") &&
+                    (!etag || (strlen(etag) > 1 && 'W' == etag[0] && '/' == etag[1]) || !ap_proxy_liststr(c->im, etag, NULL))) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-Match specified, and it didn't - return 412");
+                }
+                else {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-Match specified, and it matched");
+                    break;
+                }
             }
-        }
 
-        /* if cache file is being updated */
-        if (c->origfp) {
-            ap_proxy_write_headers(c, c->resp_line, c->hdrs);
-            ap_proxy_send_fb(c->origfp, r, c, c->len, 1, IOBUFSIZE);
-            ap_proxy_cache_tidy(c);
-        }
-        else
-            ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
+            /*
+             * check If-Unmodified-Since
+             * 
+             * if If-Unmodified-Since is specified AND Last-Modified is
+             * specified somewhere AND If-Unmodified-Since is in the past
+             * compared to Last-Modified THEN return 412 Precondition Failed
+             */
+            if (BAD_DATE != c->ius && BAD_DATE != c->lmod) {
+                if (c->ius < c->lmod) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-Unmodified-Since specified, but it wasn't - return 412");
+                }
+                else {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-Unmodified-Since specified, and it was unmodified");
+                    break;
+                }
+            }
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Use your cached copy, conditional precondition failed.");
-        return HTTP_PRECONDITION_FAILED;
-    }
+            /* if cache file is being updated */
+            if (c->origfp) {
+                ap_proxy_write_headers(c, c->resp_line, c->hdrs);
+                ap_proxy_send_fb(c->origfp, r, c, c->len, 1, IOBUFSIZE);
+                ap_proxy_cache_tidy(c);
+            }
+            else
+                ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
 
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Use your cached copy, conditional precondition failed.");
+            return HTTP_PRECONDITION_FAILED;
+        }
 
-    /* check for If-None-Match, If-Modified-Since */
-    while (1) {
 
-        /* check for existance of If-None-Match and If-Modified-Since
-         *
-         * if neither of these headers have been set, then the request
-         * is not conditional, and we just send the cached response and
-         * be done with it.
-         */
-        if (!c->inm && BAD_DATE == c->ims) {
-            break;
-        }
+        /* check for If-None-Match, If-Modified-Since */
+        while (1) {
 
-        /* check If-None-Match
-         *
-         * we check if the Etag on the cached file is in the list of Etags
-         * in the If-None-Match field. The comparison must be a strong comparison,
-         * so the Etag cannot be marked as weak. If the comparision fails
-         * we return 412 Precondition Failed.
-         *
-         * if If-None-Match is specified:
-         * if If-None-Match is a "*" THEN 304
-         * else if Etag is specified AND we get a match THEN 304
-         * else if Weak Etag is specified AND we get a match THEN 304
-         * else sent the original object
-         */
-        if (c->inm) {
-            if (!strcmp(c->inm, "*")) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-None-Match: * specified, return 304");
+            /*
+             * check for existance of If-None-Match and If-Modified-Since
+             * 
+             * if neither of these headers have been set, then the request is
+             * not conditional, and we just send the cached response and be
+             * done with it.
+             */
+            if (!c->inm && BAD_DATE == c->ims) {
+                break;
             }
-            else if (etag && ap_proxy_liststr(c->inm, etag, NULL)) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-None-Match: specified and we got a strong match - return 304");
+
+            /*
+             * check If-None-Match
+             * 
+             * we check if the Etag on the cached file is in the list of Etags
+             * in the If-None-Match field. The comparison must be a strong
+             * comparison, so the Etag cannot be marked as weak. If the
+             * comparision fails we return 412 Precondition Failed.
+             * 
+             * if If-None-Match is specified: if If-None-Match is a "*" THEN 304
+             * else if Etag is specified AND we get a match THEN 304 else if
+             * Weak Etag is specified AND we get a match THEN 304 else sent
+             * the original object
+             */
+            if (c->inm) {
+                if (!strcmp(c->inm, "*")) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-None-Match: * specified, return 304");
+                }
+                else if (etag && ap_proxy_liststr(c->inm, etag, NULL)) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-None-Match: specified and we got a strong match - return 304");
+                }
+                else if (wetag && ap_proxy_liststr(c->inm, wetag, NULL)) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-None-Match specified, and we got a weak match - return 304");
+                }
+                else
+                    break;
             }
-            else if (wetag && ap_proxy_liststr(c->inm, wetag, NULL)) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-None-Match specified, and we got a weak match - return 304");
+
+            /*
+             * check If-Modified-Since
+             * 
+             * if If-Modified-Since is specified AND Last-Modified is specified
+             * somewhere: if last modification date is earlier than
+             * If-Modified-Since THEN 304 else send the original object
+             */
+            if (BAD_DATE != c->ims && BAD_DATE != c->lmod) {
+                if (c->ims >= c->lmod) {
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "If-Modified-Since specified and not modified, try return 304");
+                }
+                else
+                    break;
             }
-            else
-                break;
-        }
 
-        /* check If-Modified-Since
-         *
-         * if If-Modified-Since is specified AND
-         * Last-Modified is specified somewhere:
-         * if last modification date is earlier than If-Modified-Since THEN 304
-         * else send the original object
-         */
-        if (BAD_DATE != c->ims && BAD_DATE != c->lmod) {
-            if (c->ims >= c->lmod) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "If-Modified-Since specified and not modified, try return 304");
+
+            /* are we updating the cache file? */
+            if (c->origfp) {
+                ap_proxy_write_headers(c, c->resp_line, c->hdrs);
+                ap_proxy_send_fb(c->origfp, r, c, c->len, 1, IOBUFSIZE);
+                ap_proxy_cache_tidy(c);
             }
             else
-                break;
-        }
-
+                ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
 
-        /* are we updating the cache file? */
-        if (c->origfp) {
-            ap_proxy_write_headers(c, c->resp_line, c->hdrs);
-            ap_proxy_send_fb(c->origfp, r, c, c->len, 1, IOBUFSIZE);
-            ap_proxy_cache_tidy(c);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Use local copy, cached file hasn't changed");
+            return HTTP_NOT_MODIFIED;
         }
-        else
-            ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Use local copy, cached file hasn't changed");
-        return HTTP_NOT_MODIFIED;
-    }
 
+        /* No conditional - just send it cousin! */
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Local copy modified, send it");
+        r->status_line = strchr(c->resp_line, ' ') + 1;
+        r->status = c->status;
 
-    /* No conditional - just send it cousin! */
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Local copy modified, send it");
-    r->status_line = strchr(c->resp_line, ' ') + 1;
-    r->status = c->status;
+        /* Prepare and send headers to client */
+        ap_overlap_tables(r->headers_out, c->hdrs, AP_OVERLAP_TABLES_SET);
+        /* make sure our X-Cache header does not stomp on a previous header */
+        ap_table_mergen(r->headers_out, "X-Cache", c->xcache);
 
-    /* Prepare and send headers to client */
-    ap_overlap_tables(r->headers_out, c->hdrs, AP_OVERLAP_TABLES_SET);
-    /* make sure our X-Cache header does not stomp on a previous header */
-    ap_table_mergen(r->headers_out, "X-Cache", c->xcache);
+        /* content type is already set in the headers */
+        r->content_type = ap_table_get(r->headers_out, "Content-Type");
 
-    /* content type is already set in the headers */
-    r->content_type = ap_table_get(r->headers_out, "Content-Type");
+        /* cookies are special: they must not be merged (stupid browsers) */
+        ap_proxy_table_unmerge(r->pool, r->headers_out, "Set-Cookie");
+        ap_proxy_table_unmerge(r->pool, r->headers_out, "Set-Cookie2");
 
-    /* cookies are special: they must not be merged (stupid browsers) */
-    ap_proxy_table_unmerge(r->pool, r->headers_out, "Set-Cookie");
-    ap_proxy_table_unmerge(r->pool, r->headers_out, "Set-Cookie2");
+        ap_send_http_header(r);
 
-    ap_send_http_header(r);
+        /* are we rewriting the cache file? */
+        if (c->origfp) {
+            ap_proxy_write_headers(c, c->resp_line, c->hdrs);
+            ap_proxy_send_fb(c->origfp, r, c, c->len, r->header_only, IOBUFSIZE);
+            ap_proxy_cache_tidy(c);
+            return OK;
+        }
 
-    /* are we rewriting the cache file? */
-    if (c->origfp) {
-        ap_proxy_write_headers(c, c->resp_line, c->hdrs);
-        ap_proxy_send_fb(c->origfp, r, c, c->len, r->header_only, IOBUFSIZE);
-        ap_proxy_cache_tidy(c);
-        return OK;
-    }
+        /* no, we not */
+        if (!r->header_only) {
+            ap_proxy_send_fb(cachefp, r, NULL, c->len, 0, IOBUFSIZE);
+        }
+        else {
+            ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
+        }
 
-    /* no, we not */
-    if (!r->header_only) {
-        ap_proxy_send_fb(cachefp, r, NULL, c->len, 0, IOBUFSIZE);
-    }
-    else {
-        ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
+        return OK;
     }
 
-    return OK;
-}
-
 
 /*
  * Call this to test for a resource in the cache
@@ -922,80 +919,83 @@ int ap_proxy_cache_conditional(request_rec *r, cache_req *c, BUFF *cachefp)
  *         if last modified after if-modified-since then add
  *            last modified date to request
  */
-int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
-                      cache_req **cr)
-{
-    const char *datestr, *pragma_req = NULL, *pragma_cresp = NULL, *cc_req = NULL, *cc_cresp = NULL, *vary = NULL;
-    cache_req *c;
-    time_t now;
-    BUFF *cachefp;
-    int i;
-    void *sconf = r->server->module_config;
-    proxy_server_conf *pconf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
-    const char *agestr = NULL;
-    char *val;
-    time_t age_c = 0;
-    time_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale, minfresh;
-
-    c = ap_pcalloc(r->pool, sizeof(cache_req));
-    *cr = c;
-    c->req = r;
-    c->url = ap_pstrdup(r->pool, url);
-    c->filename = NULL;
-    c->tempfile = NULL;
-    c->fp = NULL;
-    c->origfp = NULL;
-    c->version = 0;
-    c->len = -1;
-    c->req_hdrs = NULL;   
-    c->hdrs = NULL;
-    c->xcache = NULL;
-
-    /* get the If-Modified-Since date of the request, if it exists */
-    c->ims = BAD_DATE;
-    datestr = ap_table_get(r->headers_in, "If-Modified-Since");
-    if (datestr != NULL) {
-        /* this may modify the value in the original table */
-      datestr = ap_proxy_date_canon(r->pool, datestr);
-      c->ims = ap_parseHTTPdate(datestr);
-      if (c->ims == BAD_DATE)        /* bad or out of range date; remove it */
-         ap_table_unset(r->headers_in, "If-Modified-Since");
-    }
+    int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf * conf,
+                                 cache_req **cr){
+        const char *datestr, *pragma_req = NULL, *pragma_cresp = NULL,
+            *cc_req = NULL, *cc_cresp = NULL, *vary = NULL;
+        cache_req *c;
+        time_t now;
+        BUFF *cachefp;
+        int i;
+        void *sconf = r->server->module_config;
+        proxy_server_conf *pconf =
+        (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
+                          const char *agestr = NULL;
+        char *val;
+        time_t age_c = 0;
+        time_t age, maxage_req, maxage_cresp, maxage, smaxage, maxstale,
+               minfresh;
+
+               c = ap_pcalloc(r->pool, sizeof(cache_req));
+              *cr = c;
+               c->req = r;
+               c->url = ap_pstrdup(r->pool, url);
+               c->filename = NULL;
+               c->tempfile = NULL;
+               c->fp = NULL;
+               c->origfp = NULL;
+               c->version = 0;
+               c->len = -1;
+               c->req_hdrs = NULL;
+               c->hdrs = NULL;
+               c->xcache = NULL;
+
+        /* get the If-Modified-Since date of the request, if it exists */
+               c->ims = BAD_DATE;
+               datestr = ap_table_get(r->headers_in, "If-Modified-Since");
+        if     (datestr != NULL) {
+            /* this may modify the value in the original table */
+            datestr = ap_proxy_date_canon(r->pool, datestr);
+            c->ims = ap_parseHTTPdate(datestr);
+            if (c->ims == BAD_DATE)     /* bad or out of range date; remove
+                                         * it */
+                ap_table_unset(r->headers_in, "If-Modified-Since");
+        }
 
 /* get the If-Unmodified-Since date of the request, if it exists */
-    c->ius = BAD_DATE;
-    datestr = ap_table_get(r->headers_in, "If-Unmodified-Since");
-    if (datestr != NULL) {
-        /* this may modify the value in the original table */
-      datestr = ap_proxy_date_canon(r->pool, datestr); 
-      c->ius = ap_parseHTTPdate(datestr);
-      if (c->ius == BAD_DATE) /* bad or out of range date; remove it */
-          ap_table_unset(r->headers_in, "If-Unmodified-Since");
-    }
-     
+            c->ius = BAD_DATE;
+        datestr = ap_table_get(r->headers_in, "If-Unmodified-Since");
+        if (datestr != NULL) {
+            /* this may modify the value in the original table */
+            datestr = ap_proxy_date_canon(r->pool, datestr);
+            c->ius = ap_parseHTTPdate(datestr);
+            if (c->ius == BAD_DATE)     /* bad or out of range date; remove
+                                         * it */
+                ap_table_unset(r->headers_in, "If-Unmodified-Since");
+        }
+
 /* get the If-Match of the request, if it exists */
-    c->im = ap_table_get(r->headers_in, "If-Match");
-     
+        c->im = ap_table_get(r->headers_in, "If-Match");
+
 /* get the If-None-Match of the request, if it exists */
-    c->inm = ap_table_get(r->headers_in, "If-None-Match");
+        c->inm = ap_table_get(r->headers_in, "If-None-Match");
 
 /* find the filename for this cache entry */
-    if (conf->root != NULL) {
-        char hashfile[66];
-        ap_proxy_hash(url, hashfile, pconf->cache.dirlevels, pconf->cache.dirlength);
-      c->filename = ap_pstrcat(r->pool, conf->root, "/", hashfile, NULL);
-    }
-    else {
-      c->filename = NULL;
-      c->fp = NULL;
-      ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "No CacheRoot, so no caching. Declining.");
-      return DECLINED;
-    }
+        if (conf->root != NULL) {
+            char hashfile[66];
+            ap_proxy_hash(url, hashfile, pconf->cache.dirlevels, pconf->cache.dirlength);
+            c->filename = ap_pstrcat(r->pool, conf->root, "/", hashfile, NULL);
+        }
+        else {
+            c->filename = NULL;
+            c->fp = NULL;
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "No CacheRoot, so no caching. Declining.");
+            return DECLINED;
+        }
 
 /* find certain cache controlling headers */
-    pragma_req = ap_table_get(r->headers_in, "Pragma");
-    cc_req = ap_table_get(r->headers_in, "Cache-Control");
+        pragma_req = ap_table_get(r->headers_in, "Pragma");
+        cc_req = ap_table_get(r->headers_in, "Cache-Control");
 
 /* first things first - does the request allow us to return
  * cached information at all? If not, just decline the request.
@@ -1010,277 +1010,291 @@ int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  * we are not supposed to store this request at all. Behave as a tunnel.
  *
  */
-    if (ap_proxy_liststr(cc_req, "no-store", NULL)) {
+        if (ap_proxy_liststr(cc_req, "no-store", NULL)) {
 
 /* delete the previously cached file */
-      if (c->filename)
-          unlink(c->filename);
-      c->fp = NULL;
-      c->filename = NULL;
-      ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "no-store forbids caching. Declining.");
-      return DECLINED;
-    }
+            if (c->filename)
+                unlink(c->filename);
+            c->fp = NULL;
+            c->filename = NULL;
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "no-store forbids caching. Declining.");
+            return DECLINED;
+        }
 
 /* if the cache file exists, open it */
-    cachefp = NULL;
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Request for %s, pragma_req=%s, ims=%ld", url,
-             pragma_req, c->ims);
+        cachefp = NULL;
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Request for %s, pragma_req=%s, ims=%ld", url,
+                     pragma_req, c->ims);
 /* find out about whether the request can access the cache */
-    if (c->filename != NULL && r->method_number == M_GET &&
-        strlen(url) < 1024 ) {
-      cachefp = ap_proxy_open_cachefile(r, c->filename); 
-    }
+        if (c->filename != NULL && r->method_number == M_GET &&
+            strlen(url) < 1024) {
+            cachefp = ap_proxy_open_cachefile(r, c->filename);
+        }
 
 
-    /* if a cache file exists, try reading body and headers from cache file */
-    if (cachefp != NULL) {
-        i = rdcache(r, cachefp, c);
-        if (i == -1)
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                         "proxy: error reading cache file %s", 
-                         c->filename);
-        else if (i == 0)
-            ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
+        /*
+         * if a cache file exists, try reading body and headers from cache
+         * file
+         */
+        if (cachefp != NULL) {
+            i = rdcache(r, cachefp, c);
+            if (i == -1)
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
+                              "proxy: error reading cache file %s",
+                              c->filename);
+            else if (i == 0)
+                ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, r,
                          "proxy: bad (short?) cache file: %s", c->filename);
-        if (i != 1) {
-            ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
-            cachefp = NULL;
-        }
-        if (c->hdrs) {
-            cc_cresp = ap_table_get(c->hdrs, "Cache-Control");
-            pragma_cresp = ap_table_get(c->hdrs, "Pragma");
-            vary = ap_table_get(c->hdrs, "Vary");
-            if ((agestr = ap_table_get(c->hdrs, "Age"))) {
-                age_c = atoi(agestr);
+            if (i != 1) {
+                ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
+                cachefp = NULL;
+            }
+            if (c->hdrs) {
+                cc_cresp = ap_table_get(c->hdrs, "Cache-Control");
+                pragma_cresp = ap_table_get(c->hdrs, "Pragma");
+                vary = ap_table_get(c->hdrs, "Vary");
+                if ((agestr = ap_table_get(c->hdrs, "Age"))) {
+                    age_c = atoi(agestr);
+                }
             }
         }
-    }
 
-    /* if a cache file does not exist, create empty header array */
+        /* if a cache file does not exist, create empty header array */
 /* fixed?  in this case, we want to get the headers from the remote server
    it will be handled later if we don't do this (I hope ;-)
 
     if (cachefp == NULL)
         c->hdrs = ap_make_table(r->pool, 20);
 */
-    /* FIXME: Shouldn't we check the URL somewhere? */
-
-    /* Check Content-Negotiation - Vary
-     *
-     * At this point we need to make sure that the object we found in the cache
-     * is the same object that would be delivered to the client, when the
-     * effects of content negotiation are taken into effect.
-     *
-     * In plain english, we want to make sure that a language-negotiated
-     * document in one language is not given to a client asking for a
-     * language negotiated document in a different language by mistake.
-     *
-     * RFC2616 13.6 and 14.44 describe the Vary mechanism.
-     */
-    if (c->hdrs && c->req_hdrs) {
-        char *vary = ap_pstrdup(r->pool, ap_table_get(c->hdrs, "Vary"));
-
-        while (vary && *vary) {
-            char *name = vary;
-            const char *h1, *h2;
-
-            /* isolate header name */
-            while (*vary && !ap_isspace(*vary) && (*vary != ','))
-                ++vary;
-            while (*vary && (ap_isspace(*vary) || (*vary == ','))) {
-                *vary = '\0';
-                ++vary;
-            }
-
-            /* is this header in the request and the header in the cached
-             * request identical? If not, we give up and do a straight get */
-            h1 = ap_table_get(r->headers_in, name);
-            h2 = ap_table_get(c->req_hdrs, name);
-            if (h1 == h2) {
-                /* both headers NULL, so a match - do nothing */
-            }
-            else if (h1 && h2 && !strcmp(h1, h2)) {
-                /* both headers exist and are equal - do nothing */
-            }
-            else {
-
-                /* headers do not match, so Vary failed */
-                c->fp = cachefp;
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Vary header mismatch - object must be fetched from scratch. Declining.");
-                return DECLINED;
+        /* FIXME: Shouldn't we check the URL somewhere? */
+
+        /*
+         * Check Content-Negotiation - Vary
+         * 
+         * At this point we need to make sure that the object we found in the
+         * cache is the same object that would be delivered to the client,
+         * when the effects of content negotiation are taken into effect.
+         * 
+         * In plain english, we want to make sure that a language-negotiated
+         * document in one language is not given to a client asking for a
+         * language negotiated document in a different language by mistake.
+         * 
+         * RFC2616 13.6 and 14.44 describe the Vary mechanism.
+         */
+        if (c->hdrs && c->req_hdrs) {
+            char *vary = ap_pstrdup(r->pool, ap_table_get(c->hdrs, "Vary"));
+
+            while (vary && *vary) {
+                char *name = vary;
+                const char *h1, *h2;
+
+                /* isolate header name */
+                while (*vary && !ap_isspace(*vary) && (*vary != ','))
+                    ++vary;
+                while (*vary && (ap_isspace(*vary) || (*vary == ','))) {
+                    *vary = '\0';
+                    ++vary;
+                }
+
+                /*
+                 * is this header in the request and the header in the cached
+                 * request identical? If not, we give up and do a straight
+                 * get
+                 */
+                h1 = ap_table_get(r->headers_in, name);
+                h2 = ap_table_get(c->req_hdrs, name);
+                if (h1 == h2) {
+                    /* both headers NULL, so a match - do nothing */
+                }
+                else if (h1 && h2 && !strcmp(h1, h2)) {
+                    /* both headers exist and are equal - do nothing */
+                }
+                else {
+
+                    /* headers do not match, so Vary failed */
+                    c->fp = cachefp;
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Vary header mismatch - object must be fetched from scratch. Declining.");
+                    return DECLINED;
+                }
             }
         }
-    }
 
 
-    /* We now want to check if our cached data is still fresh. This depends
-     * on a few things, in this order:
-     *
-     * - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache
-     * no-cache in either the request or the cached response means that
-     * we must revalidate the request unconditionally, overriding any
-     * expiration mechanism. It's equivalent to max-age=0,must-revalidate.
-     *
-     * - RFC2616 14.32 Pragma: no-cache
-     * This is treated the same as Cache-Control: no-cache.
-     *
-     * - RFC2616 14.9.3 Cache-Control: max-stale, must-revalidate, proxy-revalidate
-     * if the max-stale request header exists, modify the stale calculations
-     * below so that an object can be at most <max-stale> seconds stale before
-     * we request a revalidation, _UNLESS_ a must-revalidate or
-     * proxy-revalidate cached response header exists to stop us doing this.
-     *
-     * - RFC2616 14.9.3 Cache-Control: s-maxage
-     * the origin server specifies the maximum age an object can be before
-     * it is considered stale. This directive has the effect of proxy|must
-     * revalidate, which in turn means simple ignore any max-stale setting.
-     *
-     * - RFC2616 14.9.4 Cache-Control: max-age
-     * this header can appear in both requests and responses. If both are
-     * specified, the smaller of the two takes priority.
-     *
-     * - RFC2616 14.21 Expires:
-     * if this request header exists in the cached entity, and it's value is
-     * in the past, it has expired.
-     * 
-     */
+        /*
+         * We now want to check if our cached data is still fresh. This
+         * depends on a few things, in this order:
+         * 
+         * - RFC2616 14.9.4 End to end reload, Cache-Control: no-cache no-cache
+         * in either the request or the cached response means that we must
+         * revalidate the request unconditionally, overriding any expiration
+         * mechanism. It's equivalent to max-age=0,must-revalidate.
+         * 
+         * - RFC2616 14.32 Pragma: no-cache This is treated the same as
+         * Cache-Control: no-cache.
+         * 
+         * - RFC2616 14.9.3 Cache-Control: max-stale, must-revalidate,
+         * proxy-revalidate if the max-stale request header exists, modify
+         * the stale calculations below so that an object can be at most
+         * <max-stale> seconds stale before we request a revalidation,
+         * _UNLESS_ a must-revalidate or proxy-revalidate cached response
+         * header exists to stop us doing this.
+         * 
+         * - RFC2616 14.9.3 Cache-Control: s-maxage the origin server specifies
+         * the maximum age an object can be before it is considered stale.
+         * This directive has the effect of proxy|must revalidate, which in
+         * turn means simple ignore any max-stale setting.
+         * 
+         * - RFC2616 14.9.4 Cache-Control: max-age this header can appear in
+         * both requests and responses. If both are specified, the smaller of
+         * the two takes priority.
+         * 
+         * - RFC2616 14.21 Expires: if this request header exists in the cached
+         * entity, and it's value is in the past, it has expired.
+         * 
+         */
 
-    /* calculate age of object */
-    age = ap_proxy_current_age(c, age_c);
+        /* calculate age of object */
+        age = ap_proxy_current_age(c, age_c);
 
-    /* extract s-maxage */
-    if (cc_cresp && ap_proxy_liststr(cc_cresp, "s-maxage", &val))
-        smaxage = atoi(val);
-    else
-        smaxage = -1;
+        /* extract s-maxage */
+        if (cc_cresp && ap_proxy_liststr(cc_cresp, "s-maxage", &val))
+            smaxage = atoi(val);
+        else
+            smaxage = -1;
 
-    /* extract max-age from request */
-    if (cc_req && ap_proxy_liststr(cc_req, "max-age", &val))
-        maxage_req =  atoi(val);
-    else
-        maxage_req = -1;
+        /* extract max-age from request */
+        if (cc_req && ap_proxy_liststr(cc_req, "max-age", &val))
+            maxage_req = atoi(val);
+        else
+            maxage_req = -1;
 
-    /* extract max-age from response */
-    if (cc_cresp && ap_proxy_liststr(cc_cresp, "max-age", &val))
-        maxage_cresp =  atoi(val);
-    else
-        maxage_cresp = -1;
+        /* extract max-age from response */
+        if (cc_cresp && ap_proxy_liststr(cc_cresp, "max-age", &val))
+            maxage_cresp = atoi(val);
+        else
+            maxage_cresp = -1;
 
-    /* if both maxage request and response, the smaller one takes priority */
-    if (-1 == maxage_req)
-        maxage = maxage_cresp;
-    else if (-1 == maxage_cresp)
-        maxage = maxage_req;
-    else
-        maxage = MIN(maxage_req, maxage_cresp);
+        /*
+         * if both maxage request and response, the smaller one takes
+         * priority
+         */
+        if (-1 == maxage_req)
+            maxage = maxage_cresp;
+        else if (-1 == maxage_cresp)
+            maxage = maxage_req;
+        else
+            maxage = MIN(maxage_req, maxage_cresp);
 
-    /* extract max-stale */
-    if (cc_req && ap_proxy_liststr(cc_req, "max-stale", &val))
-        maxstale =  atoi(val);
-    else
-        maxstale = 0;
+        /* extract max-stale */
+        if (cc_req && ap_proxy_liststr(cc_req, "max-stale", &val))
+            maxstale = atoi(val);
+        else
+            maxstale = 0;
 
-    /* extract min-fresh */
-    if (cc_req && ap_proxy_liststr(cc_req, "min-fresh", &val))
-        minfresh =  atoi(val);
-    else
-        minfresh = 0;
+        /* extract min-fresh */
+        if (cc_req && ap_proxy_liststr(cc_req, "min-fresh", &val))
+            minfresh = atoi(val);
+        else
+            minfresh = 0;
 
-    /* override maxstale if must-revalidate or proxy-revalidate */
-    if (maxstale && ( (cc_cresp && ap_proxy_liststr(cc_cresp, "must-revalidate", NULL)) || (cc_cresp && ap_proxy_liststr(cc_cresp, "proxy-revalidate", NULL)) ))
-        maxstale = 0;
+        /* override maxstale if must-revalidate or proxy-revalidate */
+        if (maxstale && ((cc_cresp && ap_proxy_liststr(cc_cresp, "must-revalidate", NULL)) || (cc_cresp && ap_proxy_liststr(cc_cresp, "proxy-revalidate", NULL))))
+            maxstale = 0;
 
-    now = time(NULL);
-    if (cachefp != NULL &&
+        now = time(NULL);
+        if (cachefp != NULL &&
 
         /* handle no-cache */
-        !( (cc_req && ap_proxy_liststr(cc_req, "no-cache", NULL)) ||
-          (pragma_req && ap_proxy_liststr(pragma_req, "no-cache", NULL)) ||
-          (cc_cresp && ap_proxy_liststr(cc_cresp, "no-cache", NULL)) ||
-          (pragma_cresp && ap_proxy_liststr(pragma_cresp, "no-cache", NULL)) ) &&
+            !((cc_req && ap_proxy_liststr(cc_req, "no-cache", NULL)) ||
+           (pragma_req && ap_proxy_liststr(pragma_req, "no-cache", NULL)) ||
+              (cc_cresp && ap_proxy_liststr(cc_cresp, "no-cache", NULL)) ||
+              (pragma_cresp && ap_proxy_liststr(pragma_cresp, "no-cache", NULL))) &&
 
         /* handle expiration */
-        ( (-1 < smaxage && age < (smaxage - minfresh)) ||
-          (-1 < maxage && age < (maxage + maxstale - minfresh)) ||
-          (c->expire != BAD_DATE && age < (c->expire - c->date + maxstale - minfresh)) )
+            ((-1 < smaxage && age < (smaxage - minfresh)) ||
+             (-1 < maxage && age < (maxage + maxstale - minfresh)) ||
+             (c->expire != BAD_DATE && age < (c->expire - c->date + maxstale - minfresh)))
+            ) {
 
-        ) {
+            /* it's fresh darlings... */
 
-        /* it's fresh darlings... */
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Unexpired data available");
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Unexpired data available");
+            /* set age header on response */
+            ap_table_set(c->hdrs, "Age",
+                         ap_psprintf(r->pool, "%lu", (unsigned long)age));
 
-        /* set age header on response */
-        ap_table_set(c->hdrs, "Age",
-                        ap_psprintf(r->pool, "%lu", (unsigned long)age));
+            /* add warning if maxstale overrode freshness calculation */
+            if (!((-1 < smaxage && age < smaxage) ||
+                  (-1 < maxage && age < maxage) ||
+                  (c->expire != BAD_DATE && (c->expire - c->date) > age))) {
+                /* make sure we don't stomp on a previous warning */
+                ap_table_merge(c->hdrs, "Warning", "110 Response is stale");
+            }
 
-        /* add warning if maxstale overrode freshness calculation */
-        if (!( (-1 < smaxage && age < smaxage) ||
-             (-1 < maxage && age < maxage) ||
-             (c->expire != BAD_DATE && (c->expire - c->date) > age) )) {
-            /* make sure we don't stomp on a previous warning */
-            ap_table_merge(c->hdrs, "Warning", "110 Response is stale");
-        }
+            /* check conditionals (If-Modified-Since, etc) */
+            c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), NULL);
+            return ap_proxy_cache_conditional(r, c, cachefp);
 
-        /* check conditionals (If-Modified-Since, etc) */
-        c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), NULL);
-        return ap_proxy_cache_conditional(r, c, cachefp);
 
+        }
 
-    }
+        /*
+         * at this point we have determined our cached data needs
+         * revalidation but first - we check 1 thing:
+         * 
+         * RFC2616 14.9.4 - if "only-if-cached" specified, send a 504 Gateway
+         * Timeout - we're not allowed to revalidate the object
+         */
+        if (ap_proxy_liststr(cc_req, "only-if-cached", NULL)) {
+            if (cachefp)
+                ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
+            return HTTP_GATEWAY_TIME_OUT;
+        }
 
-    /* at this point we have determined our cached data needs revalidation
-     * but first - we check 1 thing:
-     *
-     * RFC2616 14.9.4 - if "only-if-cached" specified, send a
-     * 504 Gateway Timeout - we're not allowed to revalidate the object
-     */
-    if (ap_proxy_liststr(cc_req, "only-if-cached", NULL)) {
-        if (cachefp)
-            ap_pclosef(r->pool, ap_bfileno(cachefp, B_WR));
-        return HTTP_GATEWAY_TIME_OUT;
-    }
 
+        /*
+         * If we already have cached data and a last-modified date, and it is
+         * not a head request, then add an If-Modified-Since.
+         * 
+         * If we also have an Etag, then the object must have come from an
+         * HTTP/1.1 server. Add an If-None-Match as well.
+         * 
+         * See RFC2616 13.3.4
+         */
 
-    /* If we already have cached data and a last-modified date, and it is
-     * not a head request, then add an If-Modified-Since.
-     *
-     * If we also have an Etag, then the object must have come from
-     * an HTTP/1.1 server. Add an If-None-Match as well.
-     *
-     * See RFC2616 13.3.4
-     */
+        if (cachefp != NULL && !r->header_only) {
 
-    if (cachefp != NULL && !r->header_only) {
+            const char *etag = ap_table_get(c->hdrs, "Etag");
 
-        const char *etag = ap_table_get(c->hdrs, "Etag");
+            /* If-Modified-Since */
+            if (c->lmod != BAD_DATE) {
+                /*
+                 * use the later of the one from the request and the
+                 * last-modified date from the cache
+                 */
+                if (c->ims == BAD_DATE || c->ims < c->lmod) {
+                    const char *q;
 
-        /* If-Modified-Since */
-        if (c->lmod != BAD_DATE) {
-            /* use the later of the one from the request and the last-modified date
-             * from the cache */
-            if (c->ims == BAD_DATE || c->ims < c->lmod) {
-                const char *q;
+                    if ((q = ap_table_get(c->hdrs, "Last-Modified")) != NULL)
+                        ap_table_set(r->headers_in, "If-Modified-Since", (char *)q);
+                }
+            }
 
-                if ((q = ap_table_get(c->hdrs, "Last-Modified")) != NULL)
-                    ap_table_set(r->headers_in, "If-Modified-Since", (char *) q);
+            /* If-None-Match */
+            if (etag) {
+                ap_table_set(r->headers_in, "If-None-Match", etag);
             }
-        }
 
-        /* If-None-Match */
-        if (etag) {
-            ap_table_set(r->headers_in, "If-None-Match", etag);
         }
 
-    }
 
+        c->fp = cachefp;
 
-    c->fp = cachefp;
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Local copy not present or expired. Declining.");
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Local copy not present or expired. Declining.");
-
-    return DECLINED;
-}
+        return DECLINED;
+    }
 
 /*
  * Having read the response from the client, decide what to do
@@ -1294,168 +1308,183 @@ int ap_proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  *  from the cache, maybe updating the header line
  *  otherwise, delete the old cached file and open a new temporary file
  */
-int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
-                       const int is_HTTP1, int nocache)
-{
+    int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
+                                  const int is_HTTP1, int nocache){
 #if defined(ULTRIX_BRAIN_DEATH) || defined(SINIX_D_RESOLVER_BUG)
-  extern char *mktemp(char *template);
-#endif 
-    request_rec *r = c->req;
-    char *p;
-    const char *expire, *lmods, *dates, *clen;
-    time_t expc, date, lmod, now;
-    char buff[17*7+1];
-    void *sconf = r->server->module_config;
-    proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
-    const char *cc_resp;
-    table *req_hdrs;
-
-    cc_resp = ap_table_get(resp_hdrs, "Cache-Control");
-
-    c->tempfile = NULL;
-
-    /* we've received the response from the origin server */
-    
-    /* read expiry date; if a bad date, then leave it so the client can
-     * read it */
-    expire = ap_table_get(resp_hdrs, "Expires");
-    if (expire != NULL)
-        expc = ap_parseHTTPdate(expire);
-    else
-        expc = BAD_DATE;
-
-    /* read the last-modified date; if the date is bad, then delete it */
-    lmods = ap_table_get(resp_hdrs, "Last-Modified");
-    if (lmods != NULL) {
-        lmod = ap_parseHTTPdate(lmods);
-        if (lmod == BAD_DATE) {
-            /* kill last modified date */
-            lmods = NULL;
+        extern char *mktemp(char *template);
+#endif
+        request_rec *r = c->req;
+        char *p;
+             const char *expire, *lmods, *dates, *clen;
+        time_t expc, date, lmod, now;
+        char buff[17 * 7 + 1];
+        void *sconf = r->server->module_config;
+        proxy_server_conf *conf =
+        (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
+                          const char *cc_resp;
+        table *req_hdrs;
+
+              cc_resp = ap_table_get(resp_hdrs, "Cache-Control");
+
+              c->tempfile = NULL;
+
+        /* we've received the response from the origin server */
+
+        /*
+         * read expiry date; if a bad date, then leave it so the client can
+         * read it
+         */
+              expire = ap_table_get(resp_hdrs, "Expires");
+        if    (expire != NULL)
+                  expc = ap_parseHTTPdate(expire);
+        else
+                  expc = BAD_DATE;
+
+        /* read the last-modified date; if the date is bad, then delete it */
+              lmods = ap_table_get(resp_hdrs, "Last-Modified");
+        if    (lmods != NULL) {
+            lmod = ap_parseHTTPdate(lmods);
+            if (lmod == BAD_DATE) {
+                /* kill last modified date */
+                lmods = NULL;
+            }
         }
-    }
-    else
-        lmod = BAD_DATE;
+        else
+                lmod = BAD_DATE;
 
 
-    /*
-     * what responses should we not cache?
-     *
-     * At this point we decide based on the response headers whether it
-     * is appropriate _NOT_ to cache the data from the server. There are
-     * a whole lot of conditions that prevent us from caching this data.
-     * They are tested here one by one to be clear and unambiguous. */
-
-    /* RFC2616 13.4 we are allowed to cache 200, 203, 206, 300, 301 or 410
-     * We don't cache 206, because we don't (yet) cache partial responses.
-     * We include 304 Not Modified here too as this is the origin server
-     * telling us to serve the cached copy. */
-    if ((r->status != HTTP_OK && r->status != HTTP_NON_AUTHORITATIVE && r->status != HTTP_MULTIPLE_CHOICES && r->status != HTTP_MOVED_PERMANENTLY && r->status != HTTP_NOT_MODIFIED) ||
-
-    /* if a broken Expires header is present, don't cache it */
-        (expire != NULL && expc == BAD_DATE) ||
-
-    /* if the server said 304 Not Modified but we have no cache file - pass
-     * this untouched to the user agent, it's not for us. */
-        (r->status == HTTP_NOT_MODIFIED && (c == NULL || c->fp == NULL)) ||
-
-    /* 200 OK response from HTTP/1.0 and up without a Last-Modified header */
-        (r->status == HTTP_OK && lmods == NULL && is_HTTP1) ||
-
-    /* HEAD requests */
-        r->header_only ||
-
-    /* RFC2616 14.9.2 Cache-Control: no-store response indicating do not
-     * cache, or stop now if you are trying to cache it */
-        ap_proxy_liststr(cc_resp, "no-store", NULL) ||
-
-    /* RFC2616 14.9.1 Cache-Control: private
-     * this object is marked for this user's eyes only. Behave as a tunnel. */
-        ap_proxy_liststr(cc_resp, "private", NULL) ||
-
-    /* RFC2616 14.8 Authorisation:
-     * if authorisation is included in the request, we don't cache, but we
-     * can cache if the following exceptions are true:
-     * 1) If Cache-Control: s-maxage is included
-     * 2) If Cache-Control: must-revalidate is included
-     * 3) If Cache-Control: public is included
-     */
-        (ap_table_get(r->headers_in, "Authorization") != NULL
+        /*
+         * what responses should we not cache?
+         * 
+         * At this point we decide based on the response headers whether it is
+         * appropriate _NOT_ to cache the data from the server. There are a
+         * whole lot of conditions that prevent us from caching this data.
+         * They are tested here one by one to be clear and unambiguous.
+         */
 
-        && !(ap_proxy_liststr(cc_resp, "s-maxage", NULL) || ap_proxy_liststr(cc_resp, "must-revalidate", NULL) || ap_proxy_liststr(cc_resp, "public", NULL))
-        ) ||
+        /*
+         * RFC2616 13.4 we are allowed to cache 200, 203, 206, 300, 301 or
+         * 410 We don't cache 206, because we don't (yet) cache partial
+         * responses. We include 304 Not Modified here too as this is the
+         * origin server telling us to serve the cached copy.
+         */
+        if ((r->status != HTTP_OK && r->status != HTTP_NON_AUTHORITATIVE && r->status != HTTP_MULTIPLE_CHOICES && r->status != HTTP_MOVED_PERMANENTLY && r->status != HTTP_NOT_MODIFIED) ||
 
-    /* or we've been asked not to cache it above */
-        nocache) {
+        /* if a broken Expires header is present, don't cache it */
+            (expire != NULL && expc == BAD_DATE) ||
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Response is not cacheable, unlinking %s", c->filename);
+        /*
+         * if the server said 304 Not Modified but we have no cache file -
+         * pass this untouched to the user agent, it's not for us.
+         */
+         (r->status == HTTP_NOT_MODIFIED && (c == NULL || c->fp == NULL)) ||
 
-        /* close the file */
-        if (c->fp != NULL) {
-            ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
-            c->fp = NULL;
-        }
+        /*
+         * 200 OK response from HTTP/1.0 and up without a Last-Modified
+         * header
+         */
+            (r->status == HTTP_OK && lmods == NULL && is_HTTP1) ||
 
-        /* delete the previously cached file */
-        if (c->filename)
-            unlink(c->filename);
-        return DECLINED;        /* send data to client but not cache */
-    }
+        /* HEAD requests */
+            r->header_only ||
 
+        /*
+         * RFC2616 14.9.2 Cache-Control: no-store response indicating do not
+         * cache, or stop now if you are trying to cache it
+         */
+            ap_proxy_liststr(cc_resp, "no-store", NULL) ||
 
-    /* It's safe to cache the response.
-     *
-     * We now want to update the cache file header information with
-     * the new date, last modified, expire and content length and write
-     * it away to our cache file. First, we determine these values from
-     * the response, using heuristics if appropriate.
-     *
-     * In addition, we make HTTP/1.1 age calculations and write them away
-     * too.
-     */
+        /*
+         * RFC2616 14.9.1 Cache-Control: private this object is marked for
+         * this user's eyes only. Behave as a tunnel.
+         */
+            ap_proxy_liststr(cc_resp, "private", NULL) ||
+
+        /*
+         * RFC2616 14.8 Authorisation: if authorisation is included in the
+         * request, we don't cache, but we can cache if the following
+         * exceptions are true: 1) If Cache-Control: s-maxage is included 2)
+         * If Cache-Control: must-revalidate is included 3) If Cache-Control:
+         * public is included
+         */
+            (ap_table_get(r->headers_in, "Authorization") != NULL
 
-    /* Read the date. Generate one if one is not supplied */
-    dates = ap_table_get(resp_hdrs, "Date");
-    if (dates != NULL)
-        date = ap_parseHTTPdate(dates);
-    else
-        date = BAD_DATE;
+             && !(ap_proxy_liststr(cc_resp, "s-maxage", NULL) || ap_proxy_liststr(cc_resp, "must-revalidate", NULL) || ap_proxy_liststr(cc_resp, "public", NULL))
+             ) ||
+
+        /* or we've been asked not to cache it above */
+            nocache) {
+
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Response is not cacheable, unlinking %s", c->filename);
+
+            /* close the file */
+            if (c->fp != NULL) {
+                ap_pclosef(r->pool, ap_bfileno(c->fp, B_WR));
+                c->fp = NULL;
+            }
 
-    now = time(NULL);
+            /* delete the previously cached file */
+            if (c->filename)
+                unlink(c->filename);
+            return DECLINED;    /* send data to client but not cache */
+        }
+
+
+        /*
+         * It's safe to cache the response.
+         * 
+         * We now want to update the cache file header information with the new
+         * date, last modified, expire and content length and write it away
+         * to our cache file. First, we determine these values from the
+         * response, using heuristics if appropriate.
+         * 
+         * In addition, we make HTTP/1.1 age calculations and write them away
+         * too.
+         */
+
+        /* Read the date. Generate one if one is not supplied */
+        dates = ap_table_get(resp_hdrs, "Date");
+        if (dates != NULL)
+            date = ap_parseHTTPdate(dates);
+        else
+            date = BAD_DATE;
 
-    if (date == BAD_DATE) {     /* No, or bad date */
+        now = time(NULL);
+
+        if (date == BAD_DATE) { /* No, or bad date */
 /* no date header! */
 /* add one; N.B. use the time _now_ rather than when we were checking the cache
  */
-        date = now;
-        dates = ap_gm_timestr_822(r->pool, now);
-        ap_table_set(resp_hdrs, "Date", dates);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Added date header");
-    }
+            date = now;
+            dates = ap_gm_timestr_822(r->pool, now);
+            ap_table_set(resp_hdrs, "Date", dates);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Added date header");
+        }
 
 /* set response_time for HTTP/1.1 age calculations */
-    c->resp_time = now;
+        c->resp_time = now;
 
 /* check last-modified date */
-    if (lmod != BAD_DATE && lmod > date)
+        if (lmod != BAD_DATE && lmod > date)
 /* if its in the future, then replace by date */
-    {
-        lmod = date;
-        lmods = dates;
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Last modified is in the future, replacing with now");
-    }
+        {
+            lmod = date;
+            lmods = dates;
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Last modified is in the future, replacing with now");
+        }
 /* if the response did not contain the header, then use the cached version */
-    if (lmod == BAD_DATE && c->fp != NULL) {
-        lmod = c->lmod;
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Reusing cached last modified");
-    }
+        if (lmod == BAD_DATE && c->fp != NULL) {
+            lmod = c->lmod;
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Reusing cached last modified");
+        }
 
 /* we now need to calculate the expire data for the object. */
-    if (expire == NULL && c->fp != NULL) {     /* no expiry data sent in response */
-        expire = ap_table_get(c->hdrs, "Expires");
-        if (expire != NULL)
-            expc = ap_parseHTTPdate(expire);
-    }
+        if (expire == NULL && c->fp != NULL) {  /* no expiry data sent in
+                                                 * response */
+            expire = ap_table_get(c->hdrs, "Expires");
+            if (expire != NULL)
+                expc = ap_parseHTTPdate(expire);
+        }
 /* so we now have the expiry date */
 /* if no expiry date then
  *   if lastmod
@@ -1463,44 +1492,44 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
  *   else
  *      expire date = now + defaultexpire
  */
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Expiry date is %ld", (long)expc);
-    if (expc == BAD_DATE) {
-        if (lmod != BAD_DATE) {
-            double x = (double) (date - lmod) * conf->cache.lmfactor;
-            double maxex = conf->cache.maxexpire;
-            if (x > maxex)
-                x = maxex;
-            expc = now + (int) x;
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Expiry date is %ld", (long)expc);
+        if (expc == BAD_DATE) {
+            if (lmod != BAD_DATE) {
+                double x = (double)(date - lmod) * conf->cache.lmfactor;
+                double maxex = conf->cache.maxexpire;
+                if (x > maxex)
+                    x = maxex;
+                expc = now + (int)x;
+            }
+            else
+                expc = now + conf->cache.defaultexpire;
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Expiry date calculated %ld", (long)expc);
         }
-        else
-            expc = now + conf->cache.defaultexpire;
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Expiry date calculated %ld", (long)expc);
-    }
 
 /* get the content-length header */
-    clen = ap_table_get(resp_hdrs, "Content-Length");
-    if (clen == NULL)
-        c->len = -1;
-    else
-        c->len = atoi(clen);
+        clen = ap_table_get(resp_hdrs, "Content-Length");
+        if (clen == NULL)
+            c->len = -1;
+        else
+            c->len = atoi(clen);
 
 /* we have all the header information we need - write it to the cache file */
-    c->version++;
-    ap_proxy_sec2hex(date, buff + 17*(0));
-    buff[17*(1)-1] = ' ';
-    ap_proxy_sec2hex(lmod, buff + 17*(1));
-    buff[17*(2)-1] = ' '; 
-    ap_proxy_sec2hex(expc, buff + 17*(2));
-    buff[17*(3)-1] = ' ';
-    ap_proxy_sec2hex(c->version, buff + 17*(3));
-    buff[17*(4)-1] = ' ';
-    ap_proxy_sec2hex(c->req_time, buff + 17*(4));
-    buff[17*(5)-1] = ' ';
-    ap_proxy_sec2hex(c->resp_time, buff + 17*(5));
-    buff[17*(6)-1] = ' '; 
-    ap_proxy_sec2hex(c->len, buff + 17*(6));
-    buff[17*(7)-1] = '\n';
-    buff[17*(7)] = '\0';
+        c->version++;
+        ap_proxy_sec2hex(date, buff + 17 * (0));
+        buff[17 * (1) - 1] = ' ';
+        ap_proxy_sec2hex(lmod, buff + 17 * (1));
+        buff[17 * (2) - 1] = ' ';
+        ap_proxy_sec2hex(expc, buff + 17 * (2));
+        buff[17 * (3) - 1] = ' ';
+        ap_proxy_sec2hex(c->version, buff + 17 * (3));
+        buff[17 * (4) - 1] = ' ';
+        ap_proxy_sec2hex(c->req_time, buff + 17 * (4));
+        buff[17 * (5) - 1] = ' ';
+        ap_proxy_sec2hex(c->resp_time, buff + 17 * (5));
+        buff[17 * (6) - 1] = ' ';
+        ap_proxy_sec2hex(c->len, buff + 17 * (6));
+        buff[17 * (7) - 1] = '\n';
+        buff[17 * (7)] = '\0';
 
 /* Was the server response a 304 Not Modified?
  *
@@ -1510,116 +1539,116 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
  */
 
 /* if response from server 304 not modified */
-      if (r->status == HTTP_NOT_MODIFIED) {
+        if (r->status == HTTP_NOT_MODIFIED) {
 
 /* Have the headers changed?
  *
  * if not - we fulfil the request and return now.
  */
 
-        if (c->hdrs) {
-          if (!ap_proxy_table_replace(c->hdrs, resp_hdrs)) {
-              c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), " (with revalidation)", NULL);
-              return ap_proxy_cache_conditional(r, c, c->fp);
+            if (c->hdrs) {
+                if (!ap_proxy_table_replace(c->hdrs, resp_hdrs)) {
+                    c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), " (with revalidation)", NULL);
+                    return ap_proxy_cache_conditional(r, c, c->fp);
+                }
             }
-        }
-        else
-          c->hdrs = resp_hdrs;
+            else
+                c->hdrs = resp_hdrs;
 /* if we get here - the headers have changed. Go through the motions
  * of creating a new temporary cache file below, we'll then serve
  * the request like we would have in ap_proxy_cache_conditional()
  * above, and at the same time we will also rewrite the contents
  * to the new temporary file.
  */
-      }
+        }
 
-/* 
+/*
  * Ok - lets prepare and open the cached file
- * 
+ *
  * If a cached file (in c->fp) is already open, then we want to
  * update that cached file. Copy the c->fp to c->origfp and open
  * up a new one.
- *  
+ *
  * If the cached file (in c->fp) is NULL, we must open a new cached
  * file from scratch.
  *
  * The new cache file will be moved to it's final location in the
  * directory tree later, overwriting the old cache file should it exist.
- */       
+ */
 
 /* if a cache file was already open */
-    if (c->fp != NULL) {
-      c->origfp = c->fp;
-    }
+        if (c->fp != NULL) {
+            c->origfp = c->fp;
+        }
 
-    while (1) {
+        while (1) {
 /* create temporary filename */
 #ifndef TPF
 #define TMPFILESTR    "/tmpXXXXXX"
-      if (conf->cache.root == NULL) {
-          c = ap_proxy_cache_error(c);
-          break;
-      }
-      c->tempfile = ap_palloc(r->pool, strlen(conf->cache.root) + sizeof(TMPFILESTR));
-      strcpy(c->tempfile, conf->cache.root);
-      strcat(c->tempfile, TMPFILESTR);
+            if (conf->cache.root == NULL) {
+                c = ap_proxy_cache_error(c);
+                break;
+            }
+            c->tempfile = ap_palloc(r->pool, strlen(conf->cache.root) + sizeof(TMPFILESTR));
+            strcpy(c->tempfile, conf->cache.root);
+            strcat(c->tempfile, TMPFILESTR);
 #undef TMPFILESTR
-      p = mktemp(c->tempfile);
+            p = mktemp(c->tempfile);
 #else
-      if (conf->cache.root == NULL) {
-          c = ap_proxy_cache_error(c);
-          break;
-      }
-      c->tempfile = ap_palloc(r->pool, strlen(conf->cache.root) +1+ L_tmpnam);
-      strcpy(c->tempfile, conf->cache.root);
-      strcat(c->tempfile, "/");
-      p = tmpnam(NULL);
-      strcat(c->tempfile, p);
+            if (conf->cache.root == NULL) {
+                c = ap_proxy_cache_error(c);
+                break;
+            }
+            c->tempfile = ap_palloc(r->pool, strlen(conf->cache.root) + 1 + L_tmpnam);
+            strcpy(c->tempfile, conf->cache.root);
+            strcat(c->tempfile, "/");
+            p = tmpnam(NULL);
+            strcat(c->tempfile, p);
 #endif
-      if (p == NULL) {
-          c = ap_proxy_cache_error(c);
-          break;
-      }
+            if (p == NULL) {
+                c = ap_proxy_cache_error(c);
+                break;
+            }
 
-      ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Create temporary file %s", c->tempfile);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Create temporary file %s", c->tempfile);
 
 /* create the new file */
-      c->fp = ap_proxy_create_cachefile(r, c->tempfile);
-      if (NULL == c->fp) {
-          c = ap_proxy_cache_error(c);
-          break;
-      }
+            c->fp = ap_proxy_create_cachefile(r, c->tempfile);
+            if (NULL == c->fp) {
+                c = ap_proxy_cache_error(c);
+                break;
+            }
 
 /* write away the cache header and the URL */
-      if (ap_bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1) {
-          ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                       "proxy: error writing cache file(%s)", c->tempfile);
-          c = ap_proxy_cache_error(c);
-          break;
-      }
+            if (ap_bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
+                        "proxy: error writing cache file(%s)", c->tempfile);
+                c = ap_proxy_cache_error(c);
+                break;
+            }
 
 /* get original request headers */
-      if (c->req_hdrs)
-          req_hdrs = ap_copy_table(r->pool, c->req_hdrs);
-      else
-          req_hdrs = ap_copy_table(r->pool, r->headers_in);
+            if (c->req_hdrs)
+                req_hdrs = ap_copy_table(r->pool, c->req_hdrs);
+            else
+                req_hdrs = ap_copy_table(r->pool, r->headers_in);
 
 /* remove hop-by-hop headers */
-      ap_proxy_clear_connection(r->pool, req_hdrs);
+            ap_proxy_clear_connection(r->pool, req_hdrs);
 
 /* save original request headers */
-      if (c->req_hdrs)
-            ap_table_do(ap_proxy_send_hdr_line, c, c->req_hdrs, NULL);
-      else
-            ap_table_do(ap_proxy_send_hdr_line, c, r->headers_in, NULL);
-      if (ap_bputs(CRLF, c->fp) == -1) {
-          ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                      "proxy: error writing request headers terminating CRLF to %s", c->tempfile);
-          c = ap_proxy_cache_error(c);
-          break;
-      }
-      break;
-    }
+            if (c->req_hdrs)
+                ap_table_do(ap_proxy_send_hdr_line, c, c->req_hdrs, NULL);
+            else
+                ap_table_do(ap_proxy_send_hdr_line, c, r->headers_in, NULL);
+            if (ap_bputs(CRLF, c->fp) == -1) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
+                              "proxy: error writing request headers terminating CRLF to %s", c->tempfile);
+                c = ap_proxy_cache_error(c);
+                break;
+            }
+            break;
+        }
 
 /* Was the server response a 304 Not Modified?
  *
@@ -1629,39 +1658,38 @@ int ap_proxy_cache_update(cache_req *c, table *resp_hdrs,
  */
 
 /* if response from server 304 not modified */
-    if (r->status == HTTP_NOT_MODIFIED) {
+        if (r->status == HTTP_NOT_MODIFIED) {
 
 /* fulfil the request */
-      c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), " (with revalidation)", NULL);
-      return ap_proxy_cache_conditional(r, c, c->fp);
+            c->xcache = ap_pstrcat(r->pool, "HIT from ", ap_get_server_name(r), " (with revalidation)", NULL);
+            return ap_proxy_cache_conditional(r, c, c->fp);
 
+        }
+        return DECLINED;
     }
-    return DECLINED;
-}
 
-void ap_proxy_cache_tidy(cache_req *c)
-{
-    server_rec *s;
-    long int bc;
+    void ap_proxy_cache_tidy(cache_req *c){
+        server_rec *s;
+        long int bc;
 
-    if (!c || !c->fp)
-        return;
+        if  (!c || !c->fp)
+                return;
 
-    s = c->req->server;
+            s = c->req->server;
 
 /* don't care how much was sent, but rather how much was written to cache
     ap_bgetopt(c->req->connection->client, BO_BYTECT, &bc);
  */
-    bc = c->written;
+            bc = c->written;
 
-    if (c->len != -1) {
+        if  (c->len != -1) {
 /* file lengths don't match; don't cache it */
-        if (bc != c->len) {
-            ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));  /* no need to flush */
-            unlink(c->tempfile);
-            return;
+            if (bc != c->len) {
+                ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));      /* no need to flush */
+                unlink(c->tempfile);
+                return;
+            }
         }
-    }
 /* don't care if aborted, cache it if fully retrieved from host!
     else if (c->req->connection->aborted) {
         ap_pclosef(c->req->pool, c->fp->fd);    / no need to flush /
@@ -1669,85 +1697,86 @@ void ap_proxy_cache_tidy(cache_req *c)
         return;
     }
 */
-    else {
+        else {
 /* update content-length of file */
-        char buff[17];
-        off_t curpos;
-
-        c->len = bc;
-        ap_bflush(c->fp);
-        ap_proxy_sec2hex(c->len, buff);
-        curpos = lseek(ap_bfileno(c->fp, B_WR), 17*6, SEEK_SET);
-        if (curpos == -1)
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "proxy: error seeking on cache file %s", c->tempfile);
-        else if (write(ap_bfileno(c->fp, B_WR), buff, sizeof(buff) - 1) == -1)
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "proxy: error updating cache file %s", c->tempfile);
-    }
-
-    if (ap_bflush(c->fp) == -1) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                     "proxy: error writing to cache file %s",
-                     c->tempfile);
-        ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));
-        unlink(c->tempfile);
-        return;
-    }
+            char buff[17];
+            off_t curpos;
+
+            c->len = bc;
+            ap_bflush(c->fp);
+            ap_proxy_sec2hex(c->len, buff);
+            curpos = lseek(ap_bfileno(c->fp, B_WR), 17 * 6, SEEK_SET);
+            if (curpos == -1)
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                      "proxy: error seeking on cache file %s", c->tempfile);
+            else if (write(ap_bfileno(c->fp, B_WR), buff, sizeof(buff) - 1) == -1)
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                        "proxy: error updating cache file %s", c->tempfile);
+        }
 
-    if (ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR)) == -1) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                     "proxy: error closing cache file %s", c->tempfile);
-        unlink(c->tempfile);
-        return;
-    }
+        if (ap_bflush(c->fp) == -1) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                         "proxy: error writing to cache file %s",
+                         c->tempfile);
+            ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));
+            unlink(c->tempfile);
+            return;
+        }
 
-    if (unlink(c->filename) == -1 && errno != ENOENT) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                     "proxy: error deleting old cache file %s",
-                     c->tempfile);
-    }
-    else {
-        char *p;
-        proxy_server_conf *conf =
-        (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
+        if (ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR))== -1) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                         "proxy: error closing cache file %s", c->tempfile);
+            unlink(c->tempfile);
+            return;
+        }
 
-        for (p = c->filename + strlen(conf->cache.root) + 1;;) {
-            p = strchr(p, '/');
-            if (!p)
-                break;
-            *p = '\0';
+        if (unlink(c->filename) == -1 && errno != ENOENT) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                         "proxy: error deleting old cache file %s",
+                         c->tempfile);
+        }
+        else {
+            char *p;
+            proxy_server_conf *conf =
+            (proxy_server_conf *)ap_get_module_config(s->module_config, &proxy_module);
+
+            for (p = c->filename + strlen(conf->cache.root) + 1;;) {
+                p = strchr(p, '/');
+                if (!p)
+                    break;
+                *p = '\0';
 #if defined(WIN32) || defined(NETWARE)
-            if (mkdir(c->filename) < 0 && errno != EEXIST)
+                if (mkdir(c->filename) < 0 && errno != EEXIST)
 #elif defined(__TANDEM)
-            if (mkdir(c->filename, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
+                    if (mkdir(c->filename, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)
 #else
-            if (mkdir(c->filename, S_IREAD | S_IWRITE | S_IEXEC) < 0 && errno != EEXIST)
-#endif /* WIN32 */
+                if (mkdir(c->filename, S_IREAD | S_IWRITE | S_IEXEC) < 0 && errno != EEXIST)
+#endif                          /* WIN32 */
+                    ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                                 "proxy: error creating cache directory %s",
+                                 c->filename);
+                *p = '/';
+                ++p;
+            }
+#if defined(OS2) || defined(WIN32) || defined(NETWARE) || defined(MPE)
+            /* Under OS/2 use rename. */
+            if (rename(c->tempfile, c->filename) == -1)
                 ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                             "proxy: error creating cache directory %s",
-                             c->filename);
-            *p = '/';
-            ++p;
+                             "proxy: error renaming cache file %s to %s",
+                             c->tempfile, c->filename);
         }
-#if defined(OS2) || defined(WIN32) || defined(NETWARE) || defined(MPE)
-        /* Under OS/2 use rename. */
-        if (rename(c->tempfile, c->filename) == -1)
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "proxy: error renaming cache file %s to %s",
-                         c->tempfile, c->filename);
-    }
 #else
 
-        if (link(c->tempfile, c->filename) == -1)
-            ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                         "proxy: error linking cache file %s to %s",
-                         c->tempfile, c->filename);
-    }
+            if (link(c->tempfile, c->filename) == -1)
+                ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                             "proxy: error linking cache file %s to %s",
+                             c->tempfile, c->filename);
+        }
 
-    if (unlink(c->tempfile) == -1)
-        ap_log_error(APLOG_MARK, APLOG_ERR, s,
-                     "proxy: error deleting temp file %s", c->tempfile);
+        if (unlink(c->tempfile) == -1)
+            ap_log_error(APLOG_MARK, APLOG_ERR, s,
+                         "proxy: error deleting temp file %s", c->tempfile);
 #endif
 
-}
+    }
+/**INDENT** Error@1753: Stuff missing from end of file. */
index 4870e00908886fb01e849c17422bd943883b8cd5..9b955d5177621453a8c6edaef30831c9389a22d5 100644 (file)
@@ -66,7 +66,7 @@
 #include <bstring.h>            /* for IRIX, FD_SET calls bzero() */
 #endif
 
-/*  
+/*
  * This handles Netscape CONNECT method secure proxy requests.
  * A connection is opened to the specified host and data is
  * passed through between the WWW site and the browser.
@@ -75,8 +75,8 @@
  * "Tunneling SSL Through a WWW Proxy" currently at
  * http://www.mcom.com/newsref/std/tunneling_ssl.html.
  *
- * If proxyhost and proxyport are set, we send a CONNECT to 
- * the specified proxy..  
+ * If proxyhost and proxyport are set, we send a CONNECT to
+ * the specified proxy..
  *
  * FIXME: this is bad, because it does its own socket I/O
  *        instead of using the I/O in buff.c.  However,
  * FIXME: no check for r->assbackwards, whatever that is.
  */
 
-static int
-allowed_port(proxy_server_conf *conf, int port)
+static int allowed_port(proxy_server_conf *conf, int port)
 {
     int i;
-    int *list = (int *) conf->allowed_connect_ports->elts;
+    int *list = (int *)conf->allowed_connect_ports->elts;
 
-    for(i = 0; i < conf->allowed_connect_ports->nelts; i++) {
-        if(port == list[i])
+    for (i = 0; i < conf->allowed_connect_ports->nelts; i++) {
+        if (port == list[i])
             return 1;
     }
     return 0;
@@ -111,7 +110,7 @@ allowed_port(proxy_server_conf *conf, int port)
 
 
 int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
-                          const char *proxyhost, int proxyport)
+                                 const char *proxyhost, int proxyport)
 {
     struct sockaddr_in server;
     struct in_addr destaddr;
@@ -125,8 +124,8 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
 
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
-    struct noproxy_entry *npent = (struct noproxy_entry *)conf->noproxies->elts;
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
+    struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
 
     memset(&server, '\0', sizeof(server));
     server.sin_family = AF_INET;
@@ -156,22 +155,23 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
     if (conf->allowed_connect_ports->nelts == 0) {
         /* Default setting if not overridden by AllowCONNECT */
         switch (port) {
-            case DEFAULT_HTTPS_PORT:
-            case DEFAULT_SNEWS_PORT:
-                break;
-            default:
-                return HTTP_FORBIDDEN;
+        case DEFAULT_HTTPS_PORT:
+        case DEFAULT_SNEWS_PORT:
+            break;
+        default:
+            return HTTP_FORBIDDEN;
         }
-    } else if(!allowed_port(conf, port))
+    }
+    else if (!allowed_port(conf, port))
         return HTTP_FORBIDDEN;
 
     if (proxyhost) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+             "CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
     }
     else {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "CONNECT to %s on port %d", host, port);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "CONNECT to %s on port %d", host, port);
     }
 
     /* Nasty cast to work around broken terniary expressions on MSVC */
@@ -180,7 +180,7 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
 
     if (err != NULL)
         return ap_proxyerror(r,
-           proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
+            proxyhost ? HTTP_BAD_GATEWAY : HTTP_INTERNAL_SERVER_ERROR, err);
 
     sock = ap_psocket(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (sock == -1) {
@@ -190,11 +190,11 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
 
 #ifdef CHECK_FD_SETSIZE
     if (sock >= FD_SETSIZE) {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
-            "proxy_connect_handler: filedescriptor (%u) "
-            "larger than FD_SETSIZE (%u) "
-            "found, you probably need to rebuild Apache with a "
-            "larger FD_SETSIZE", sock, FD_SETSIZE);
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_WARNING, NULL,
+                     "proxy_connect_handler: filedescriptor (%u) "
+                     "larger than FD_SETSIZE (%u) "
+                     "found, you probably need to rebuild Apache with a "
+                     "larger FD_SETSIZE", sock, FD_SETSIZE);
         ap_pclosesocket(r->pool, sock);
         return HTTP_INTERNAL_SERVER_ERROR;
     }
@@ -212,73 +212,76 @@ int ap_proxy_connect_handler(request_rec *r, cache_req *c, char *url,
     if (i == -1) {
         ap_pclosesocket(r->pool, sock);
         return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, ap_pstrcat(r->pool,
-            "Could not connect to remote machine:<br>", strerror(errno), NULL));
+        "Could not connect to remote machine:<br>", strerror(errno), NULL));
     }
 
-    /* If we are connecting through a remote proxy, we need to pass
-     * the CONNECT request on to it.
+    /*
+     * If we are connecting through a remote proxy, we need to pass the
+     * CONNECT request on to it.
      */
     if (proxyport) {
-        /* FIXME: We should not be calling write() directly, but we currently
-         * have no alternative.  Error checking ignored.  Also, we force
-         * a HTTP/1.0 request to keep things simple.
+        /*
+         * FIXME: We should not be calling write() directly, but we currently
+         * have no alternative.  Error checking ignored.  Also, we force a
+         * HTTP/1.0 request to keep things simple.
          */
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "Sending the CONNECT request to the remote proxy");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "Sending the CONNECT request to the remote proxy");
         ap_snprintf(buffer, sizeof(buffer), "CONNECT %s HTTP/1.0" CRLF, r->uri);
-        send(sock, buffer, strlen(buffer),0);
+        send(sock, buffer, strlen(buffer), 0);
         ap_snprintf(buffer, sizeof(buffer),
-            "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
-        send(sock, buffer, strlen(buffer),0);
+                    "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
+        send(sock, buffer, strlen(buffer), 0);
     }
     else {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "Returning 200 OK Status");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "Returning 200 OK Status");
         ap_rvputs(r, "HTTP/1.0 200 Connection established" CRLF, NULL);
         ap_rvputs(r, "Proxy-agent: ", ap_get_server_version(), CRLF CRLF, NULL);
         ap_bflush(r->connection->client);
     }
 
-    while (1) { /* Infinite loop until error (one side closes the connection) */
+    while (1) {                 /* Infinite loop until error (one side closes
+                                 * the connection) */
         FD_ZERO(&fds);
         FD_SET(sock, &fds);
         FD_SET(ap_bfileno(r->connection->client, B_WR), &fds);
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "Going to sleep (select)");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "Going to sleep (select)");
         i = ap_select((ap_bfileno(r->connection->client, B_WR) > sock ?
-            ap_bfileno(r->connection->client, B_WR) + 1 :
-            sock + 1), &fds, NULL, NULL, NULL);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-            "Woke from select(), i=%d", i);
+                       ap_bfileno(r->connection->client, B_WR) + 1 :
+                       sock + 1), &fds, NULL, NULL, NULL);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                     "Woke from select(), i=%d", i);
 
         if (i) {
             if (FD_ISSET(sock, &fds)) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-                    "sock was set");
-                if ((nbytes = recv(sock, buffer, HUGE_STRING_LEN,0)) != 0) {
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                             "sock was set");
+                if ((nbytes = recv(sock, buffer, HUGE_STRING_LEN, 0)) != 0) {
                     if (nbytes == -1)
                         break;
                     if (send(ap_bfileno(r->connection->client, B_WR), buffer,
-                        nbytes,0) == EOF)
+                             nbytes, 0) == EOF)
                         break;
-                    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO,
-                        r->server, "Wrote %d bytes to client", nbytes);
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO,
+                             r->server, "Wrote %d bytes to client", nbytes);
                 }
                 else
                     break;
             }
             else if (FD_ISSET(ap_bfileno(r->connection->client, B_WR), &fds)) {
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server,
-                    "client->fd was set");
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server,
+                             "client->fd was set");
                 if ((nbytes = recv(ap_bfileno(r->connection->client, B_WR),
-                    buffer, HUGE_STRING_LEN, 0)) != 0) {
+                                   buffer, HUGE_STRING_LEN, 0)) != 0) {
                     if (nbytes == -1)
                         break;
                     if (send(sock, buffer, nbytes, 0) == EOF)
                         break;
-                    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO,
-                        r->server, "Wrote %d bytes to server", nbytes);
+                    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO,
+                             r->server, "Wrote %d bytes to server", nbytes);
                 }
                 else
                     break;
index 8f29738f8e2f0616c65acdfd491b1a1eec2a2c28..e845b93b07c92ea3bdcf429045be081bab517305 100644 (file)
@@ -73,7 +73,7 @@ static int decodeenc(char *x)
     int i, j, ch;
 
     if (x[0] == '\0')
-        return 0;                /* special case for no characters */
+        return 0;               /* special case for no characters */
     for (i = 0, j = 0; x[i] != '\0'; i++, j++) {
 /* decode it if not already done */
         ch = x[i];
@@ -173,10 +173,10 @@ int ap_proxy_ftp_canon(request_rec *r, char *url)
         sport[0] = '\0';
 
     r->filename = ap_pstrcat(p, "proxy:ftp://", (user != NULL) ? user : "",
-                               (password != NULL) ? ":" : "",
-                               (password != NULL) ? password : "",
+                             (password != NULL) ? ":" : "",
+                             (password != NULL) ? password : "",
                           (user != NULL) ? "@" : "", host, sport, "/", path,
-                               (parms[0] != '\0') ? ";" : "", parms, NULL);
+                             (parms[0] != '\0') ? ";" : "", parms, NULL);
 
     return OK;
 }
@@ -195,7 +195,7 @@ static int ftp_getrc(BUFF *ctrl)
         return -1;
 /* check format */
     if (len < 5 || !ap_isdigit(linebuff[0]) || !ap_isdigit(linebuff[1]) ||
-        !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
+     !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
         status = 0;
     else
         status = 100 * linebuff[0] + 10 * linebuff[1] + linebuff[2] - 111 * '0';
@@ -222,26 +222,25 @@ static int ftp_getrc(BUFF *ctrl)
 }
 
 /*
- * Like ftp_getrc but returns both the ftp status code and 
+ * Like ftp_getrc but returns both the ftp status code and
  * remembers the response message in the supplied buffer
  */
 static int ftp_getrc_msg(BUFF *ctrl, char *msgbuf, int msglen)
 {
     int len, status;
     char linebuff[100], buff[5];
-    char *mb = msgbuf,
-         *me = &msgbuf[msglen];
+    char *mb = msgbuf, *me = &msgbuf[msglen];
 
     len = ap_bgets(linebuff, sizeof linebuff, ctrl);
     if (len == -1)
         return -1;
     if (len < 5 || !ap_isdigit(linebuff[0]) || !ap_isdigit(linebuff[1]) ||
-        !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
+     !ap_isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
         status = 0;
     else
         status = 100 * linebuff[0] + 10 * linebuff[1] + linebuff[2] - 111 * '0';
 
-    mb = ap_cpystrn(mb, linebuff+4, me - mb);
+    mb = ap_cpystrn(mb, linebuff + 4, me - mb);
 
     if (linebuff[len - 1] != '\n')
         (void)ap_bskiplf(ctrl);
@@ -256,7 +255,7 @@ static int ftp_getrc_msg(BUFF *ctrl, char *msgbuf, int msglen)
             if (linebuff[len - 1] != '\n') {
                 (void)ap_bskiplf(ctrl);
             }
-            mb = ap_cpystrn(mb, linebuff+4, me - mb);
+            mb = ap_cpystrn(mb, linebuff + 4, me - mb);
         } while (memcmp(linebuff, buff, 4) != 0);
     }
     return status;
@@ -275,7 +274,8 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
     conn_rec *con = r->connection;
     pool *p = r->pool;
     char *dir, *path, *reldir, *site, *type = NULL;
-    char *basedir = ""; /* By default, path is relative to the $HOME dir */
+    char *basedir = "";         /* By default, path is relative to the $HOME
+                                 * dir */
 
     /* create default sized buffers for the stuff below */
     buf_size = IOBUFSIZE;
@@ -283,9 +283,9 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
     buf2 = ap_palloc(r->pool, buf_size);
 
     /* Save "scheme://site" prefix without password */
-    site = ap_unparse_uri_components(p, &r->parsed_uri, UNP_OMITPASSWORD|UNP_OMITPATHINFO);
+    site = ap_unparse_uri_components(p, &r->parsed_uri, UNP_OMITPASSWORD | UNP_OMITPATHINFO);
     /* ... and path without query args */
-    path = ap_unparse_uri_components(p, &r->parsed_uri, UNP_OMITSITEPART|UNP_OMITQUERY);
+    path = ap_unparse_uri_components(p, &r->parsed_uri, UNP_OMITSITEPART | UNP_OMITQUERY);
 
     /* If path began with /%2f, change the basedir */
     if (strncasecmp(path, "/%2f", 4) == 0) {
@@ -298,24 +298,24 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
 
     (void)decodeenc(path);
 
-    while (path[1] == '/') /* collapse multiple leading slashes to one */
+    while (path[1] == '/')      /* collapse multiple leading slashes to one */
         ++path;
 
     /* Copy path, strip (all except the last) trailing slashes */
     /* (the trailing slash is needed for the dir component loop below) */
     path = dir = ap_pstrcat(r->pool, path, "/", NULL);
-    for (n = strlen(path); n > 1 && path[n-1] == '/' && path[n-2] == '/'; --n)
-        path[n-1] = '\0';
+    for (n = strlen(path); n > 1 && path[n - 1] == '/' && path[n - 2] == '/'; --n)
+        path[n - 1] = '\0';
 
     /* print "ftp://host/" */
     n = ap_snprintf(buf, buf_size, DOCTYPE_HTML_3_2
-                "<html><head><title>%s%s%s</title>\n"
-                "<base href=\"%s%s%s\"></head>\n"
-                "<body><h2>Directory of "
-                "<a href=\"/\">%s</a>/",
-                site, basedir, ap_escape_html(p,path),
-                site, basedir, ap_escape_uri(p,path),
-                site);
+                    "<html><head><title>%s%s%s</title>\n"
+                    "<base href=\"%s%s%s\"></head>\n"
+                    "<body><h2>Directory of "
+                    "<a href=\"/\">%s</a>/",
+                    site, basedir, ap_escape_html(p, path),
+                    site, basedir, ap_escape_uri(p, path),
+                    site);
     total_bytes_sent += ap_proxy_bputs2(buf, con->client, c);
 
     /* Add a link to the root directory (if %2f hack was used) */
@@ -323,11 +323,10 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
         total_bytes_sent += ap_proxy_bputs2("<a href=\"/%2f/\">%2f</a>/", con->client, c);
     }
 
-    for (dir = path+1; (dir = strchr(dir, '/')) != NULL; )
-    {
+    for (dir = path + 1; (dir = strchr(dir, '/')) != NULL;) {
         *dir = '\0';
-        if ((reldir = strrchr(path+1, '/'))==NULL) {
-            reldir = path+1;
+        if ((reldir = strrchr(path + 1, '/')) == NULL) {
+            reldir = path + 1;
         }
         else
             ++reldir;
@@ -339,14 +338,15 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
         total_bytes_sent += ap_proxy_bputs2(buf, con->client, c);
         *dir = '/';
         while (*dir == '/')
-          ++dir;
+            ++dir;
     }
 
     /* If the caller has determined the current directory, and it differs */
     /* from what the client requested, then show the real name */
-    if (cwd == NULL || strncmp (cwd, path, strlen(cwd)) == 0) {
+    if (cwd == NULL || strncmp(cwd, path, strlen(cwd)) == 0) {
         ap_snprintf(buf, buf_size, "</h2>\n<hr /><pre>");
-    } else {
+    }
+    else {
         ap_snprintf(buf, buf_size, "</h2>\n(%s)\n<hr /><pre>",
                     ap_escape_html(p, cwd));
     }
@@ -357,21 +357,21 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
         if (n == -1) {          /* input error */
             if (c != NULL) {
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                    "proxy: error reading from %s", c->url);
+                              "proxy: error reading from %s", c->url);
                 c = ap_proxy_cache_error(c);
             }
             break;
         }
         if (n == 0)
-            break;                /* EOF */
+            break;              /* EOF */
 
-        if (buf[n-1] == '\n')  /* strip trailing '\n' */
+        if (buf[n - 1] == '\n') /* strip trailing '\n' */
             buf[--n] = '\0';
-        if (buf[n-1] == '\r')  /* strip trailing '\r' if present */
+        if (buf[n - 1] == '\r') /* strip trailing '\r' if present */
             buf[--n] = '\0';
 
         /* Handle unix-style symbolic link */
-        if (buf[0] == 'l' && (filename=strstr(buf, " -> ")) != NULL) {
+        if (buf[0] == 'l' && (filename = strstr(buf, " -> ")) != NULL) {
             char *link_ptr = filename;
 
             do {
@@ -382,7 +382,7 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
             *(link_ptr++) = '\0';
             ap_snprintf(buf2, buf_size, "%s <a href=\"%s\">%s %s</a>\n",
                         ap_escape_html(p, buf),
-                        ap_escape_uri(p,filename),
+                        ap_escape_uri(p, filename),
                         ap_escape_html(p, filename),
                         ap_escape_html(p, link_ptr));
             ap_cpystrn(buf, buf2, buf_size);
@@ -416,13 +416,13 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
             /* Special handling for '.' and '..': append slash to link */
             if (!strcmp(filename, ".") || !strcmp(filename, "..") || buf[0] == 'd') {
                 ap_snprintf(buf2, buf_size, "%s <a href=\"%s/\">%s</a>\n",
-                            ap_escape_html(p, buf), ap_escape_uri(p,filename),
+                         ap_escape_html(p, buf), ap_escape_uri(p, filename),
                             ap_escape_html(p, filename));
             }
             else {
                 ap_snprintf(buf2, buf_size, "%s <a href=\"%s\">%s</a>\n",
                             ap_escape_html(p, buf),
-                            ap_escape_uri(p,filename),
+                            ap_escape_uri(p, filename),
                             ap_escape_html(p, filename));
             }
             ap_cpystrn(buf, buf2, buf_size);
@@ -430,13 +430,13 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
         }
         /* else??? What about other OS's output formats? */
         else {
-            strcat(buf, "\n"); /* re-append the newline char */
+            strcat(buf, "\n");  /* re-append the newline char */
             ap_cpystrn(buf, ap_escape_html(p, buf), buf_size);
         }
 
         total_bytes_sent += ap_proxy_bputs2(buf, con->client, c);
 
-        ap_reset_timeout(r);        /* reset timeout after successfule write */
+        ap_reset_timeout(r);    /* reset timeout after successfule write */
     }
 
     total_bytes_sent += ap_proxy_bputs2("</pre><hr />\n", con->client, c);
@@ -457,23 +457,24 @@ static long int send_dir(BUFF *data, request_rec *r, cache_req *c, char *cwd)
  * Note that we "invent" a realm name which consists of the
  * ftp://user@host part of the reqest (sans password -if supplied but invalid-)
  */
-static int ftp_unauthorized (request_rec *r, int log_it)
+static int ftp_unauthorized(request_rec *r, int log_it)
 {
     r->proxyreq = NOT_PROXY;
-    /* Log failed requests if they supplied a password
-     * (log username/password guessing attempts)
+    /*
+     * Log failed requests if they supplied a password (log username/password
+     * guessing attempts)
      */
     if (log_it)
-        ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r,
+        ap_log_rerror(APLOG_MARK, APLOG_INFO | APLOG_NOERRNO, r,
                       "proxy: missing or failed auth to %s",
                       ap_unparse_uri_components(r->pool,
-                      &r->parsed_uri, UNP_OMITPATHINFO));
+                                         &r->parsed_uri, UNP_OMITPATHINFO));
 
     ap_table_setn(r->err_headers_out, "WWW-Authenticate",
                   ap_pstrcat(r->pool, "Basic realm=\"",
-                  ap_unparse_uri_components(r->pool, &r->parsed_uri,
-                                            UNP_OMITPASSWORD|UNP_OMITPATHINFO),
-                  "\"", NULL));
+                          ap_unparse_uri_components(r->pool, &r->parsed_uri,
+                                       UNP_OMITPASSWORD | UNP_OMITPATHINFO),
+                             "\"", NULL));
 
     return HTTP_UNAUTHORIZED;
 }
@@ -481,7 +482,7 @@ static int ftp_unauthorized (request_rec *r, int log_it)
 /* Set ftp server to TYPE {A,I,E} before transfer of a directory or file */
 static int ftp_set_TYPE(request_rec *r, BUFF *ctrl, char xfer_type)
 {
-    static char old_type[2] = { 'A', '\0' }; /* After logon, mode is ASCII */
+    static char old_type[2] = {'A', '\0'};      /* After logon, mode is ASCII */
     int ret = HTTP_OK;
     int rc;
 
@@ -492,7 +493,7 @@ static int ftp_set_TYPE(request_rec *r, BUFF *ctrl, char xfer_type)
     old_type[0] = xfer_type;
     ap_bvputs(ctrl, "TYPE ", old_type, CRLF, NULL);
     ap_bflush(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: TYPE %s", old_type);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: TYPE %s", old_type);
 
 /* responses: 200, 421, 500, 501, 504, 530 */
     /* 200 Command okay. */
@@ -502,37 +503,36 @@ static int ftp_set_TYPE(request_rec *r, BUFF *ctrl, char xfer_type)
     /* 504 Command not implemented for that parameter. */
     /* 530 Not logged in. */
     rc = ftp_getrc(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
     if (rc == -1 || rc == 421) {
         ap_kill_timeout(r);
         ret = ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                             "Error reading from remote server");
+                            "Error reading from remote server");
     }
     else if (rc != 200 && rc != 504) {
         ap_kill_timeout(r);
         ret = ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                             "Unable to set transfer type");
+                            "Unable to set transfer type");
     }
 /* Allow not implemented */
     else if (rc == 504)
-        /* ignore it silently */;
+         /* ignore it silently */ ;
 
     return ret;
 }
 
 /* Common cleanup routine: close open BUFFers or sockets, and return an error */
-static int
-ftp_cleanup_and_return(request_rec *r, BUFF *ctrl, BUFF *data, int csock, int dsock, int rc)
+static int ftp_cleanup_and_return(request_rec *r, BUFF *ctrl, BUFF *data, int csock, int dsock, int rc)
 {
     if (ctrl != NULL)
-      ap_bclose(ctrl);
+        ap_bclose(ctrl);
     else if (csock != -1)
-      ap_pclosesocket(r->pool, csock);
+        ap_pclosesocket(r->pool, csock);
 
     if (data != NULL)
-      ap_bclose(data);
+        ap_bclose(data);
     else if (dsock != -1)
-      ap_pclosesocket(r->pool, dsock);
+        ap_pclosesocket(r->pool, dsock);
 
     ap_kill_timeout(r);
 
@@ -564,12 +564,12 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     pool *p = r->pool;
     int one = 1;
     NET_SIZE_T clen;
-    char xfer_type = 'A'; /* after ftp login, the default is ASCII */
+    char xfer_type = 'A';       /* after ftp login, the default is ASCII */
     int get_dirlisting = 0;
 
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
     struct nocache_entry *ncent = (struct nocache_entry *) conf->nocaches->elts;
 
@@ -595,8 +595,8 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 
     host = r->parsed_uri.hostname;
     port = (r->parsed_uri.port != 0)
-            ? r->parsed_uri.port
-            : ap_default_port_for_request(r);
+        ? r->parsed_uri.port
+        : ap_default_port_for_request(r);
     path = ap_pstrdup(p, r->parsed_uri.path);
     if (path == NULL)
         path = "";
@@ -604,25 +604,27 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         while (*path == '/')
             ++path;
 
-    /* The "Authorization:" header must be checked first.
-     * We allow the user to "override" the URL-coded user [ & password ]
-     * in the Browsers' User&Password Dialog.
-     * NOTE that this is only marginally more secure than having the
-     * password travel in plain as part of the URL, because Basic Auth
-     * simply uuencodes the plain text password. 
-     * But chances are still smaller that the URL is logged regularly.
+    /*
+     * The "Authorization:" header must be checked first. We allow the user
+     * to "override" the URL-coded user [ & password ] in the Browsers'
+     * User&Password Dialog. NOTE that this is only marginally more secure
+     * than having the password travel in plain as part of the URL, because
+     * Basic Auth simply uuencodes the plain text password. But chances are
+     * still smaller that the URL is logged regularly.
      */
     if ((password = ap_table_get(r->headers_in, "Authorization")) != NULL
         && strcasecmp(ap_getword(r->pool, &password, ' '), "Basic") == 0
         && (password = ap_pbase64decode(r->pool, password))[0] != ':') {
-        /* Note that this allocation has to be made from r->connection->pool
-         * because it has the lifetime of the connection.  The other allocations
-         * are temporary and can be tossed away any time.
+        /*
+         * Note that this allocation has to be made from r->connection->pool
+         * because it has the lifetime of the connection.  The other
+         * allocations are temporary and can be tossed away any time.
          */
-        user = ap_getword_nulls (r->connection->pool, &password, ':');
+        user = ap_getword_nulls(r->connection->pool, &password, ':');
         r->connection->ap_auth_type = "Basic";
         r->connection->user = r->parsed_uri.user = user;
-        nocache = 1;    /* This resource only accessible with username/password */
+        nocache = 1;            /* This resource only accessible with
+                                 * username/password */
     }
     else if ((user = r->parsed_uri.user) != NULL) {
         user = ap_pstrdup(p, user);
@@ -632,7 +634,8 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
             decodeenc(tmp);
             password = tmp;
         }
-        nocache = 1;    /* This resource only accessible with username/password */
+        nocache = 1;            /* This resource only accessible with
+                                 * username/password */
     }
     else {
         user = "anonymous";
@@ -644,12 +647,12 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     for (i = 0; i < conf->noproxies->nelts; i++) {
         if (destaddr.s_addr == npent[i].addr.s_addr ||
             (npent[i].name != NULL &&
-              (npent[i].name[0] == '*' || strstr(host, npent[i].name) != NULL)))
+          (npent[i].name[0] == '*' || strstr(host, npent[i].name) != NULL)))
             return ap_proxyerror(r, HTTP_FORBIDDEN,
                                  "Connect to remote machine blocked");
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: connect to %s:%d", host, port);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: connect to %s:%d", host, port);
 
     parms = strchr(path, ';');
     if (parms != NULL)
@@ -665,33 +668,33 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     sock = ap_psocket(p, PF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (sock == -1) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                     "proxy: error creating socket");
+                      "proxy: error creating socket");
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
 #if !defined(TPF) && !defined(BEOS)
     if (conf->recv_buffer_size > 0
         && setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
-                       (const char *) &conf->recv_buffer_size, sizeof(int))
-            == -1) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                         "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
+                      (const char *)&conf->recv_buffer_size, sizeof(int))
+        == -1) {
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
+                      "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
     }
 #endif
 
-    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &one,
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
                    sizeof(one)) == -1) {
-#ifndef _OSD_POSIX /* BS2000 has this option "always on" */
+#ifndef _OSD_POSIX              /* BS2000 has this option "always on" */
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                     "proxy: error setting reuseaddr option: setsockopt(SO_REUSEADDR)");
+         "proxy: error setting reuseaddr option: setsockopt(SO_REUSEADDR)");
         ap_pclosesocket(p, sock);
         return HTTP_INTERNAL_SERVER_ERROR;
-#endif /*_OSD_POSIX*/
+#endif                          /* _OSD_POSIX */
     }
 
 #ifdef SINIX_D_RESOLVER_BUG
     {
-        struct in_addr *ip_addr = (struct in_addr *) *server_hp.h_addr_list;
+        struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
 
         for (; ip_addr->s_addr != 0; ++ip_addr) {
             memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
@@ -715,7 +718,7 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                       ap_proxyerror(r, HTTP_BAD_GATEWAY, ap_pstrcat(r->pool,
                                     "Could not connect to remote machine: ",
-                                    strerror(errno), NULL)));
+                                                   strerror(errno), NULL)));
     }
 
     /* record request_time for HTTP/1.1 age calculation */
@@ -726,8 +729,8 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 /* shouldn't we implement telnet control options here? */
 
 #ifdef CHARSET_EBCDIC
-    ap_bsetflag(ctrl, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 1);
-#endif /*CHARSET_EBCDIC*/
+    ap_bsetflag(ctrl, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 1);
+#endif                          /* CHARSET_EBCDIC */
 
     /* possible results: */
     /* 120 Service ready in nnn minutes. */
@@ -735,39 +738,40 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     /* 421 Service not available, closing control connection. */
     ap_hard_timeout("proxy ftp", r);
     i = ftp_getrc_msg(ctrl, resp, sizeof resp);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
     if (i == -1 || i == 421) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                    "Error reading from remote server"));
+                                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
     }
 #if 0
     if (i == 120) {
-        /* RFC2068 states:
-         * 14.38 Retry-After
+        /*
+         * RFC2068 states: 14.38 Retry-After
          * 
-         *  The Retry-After response-header field can be used with a 503 (Service
-         *  Unavailable) response to indicate how long the service is expected to
-         *  be unavailable to the requesting client. The value of this field can
-         *  be either an HTTP-date or an integer number of seconds (in decimal)
-         *  after the time of the response.
-         *     Retry-After  = "Retry-After" ":" ( HTTP-date | delta-seconds )
+         * The Retry-After response-header field can be used with a 503 (Service
+         * Unavailable) response to indicate how long the service is expected
+         * to be unavailable to the requesting client. The value of this
+         * field can be either an HTTP-date or an integer number of seconds
+         * (in decimal) after the time of the response. Retry-After  =
+         * "Retry-After" ":" ( HTTP-date | delta-seconds )
          */
-        ap_set_header("Retry-After", ap_psprintf(p, "%u", 60*wait_mins);
+/**INDENT** Error@756: Unbalanced parens */
+        ap_set_header("Retry-After", ap_psprintf(p, "%u", 60 * wait_mins);
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE, resp));
+                          ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE, resp));
     }
 #endif
     if (i != 220) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_GATEWAY, resp));
+                                  ap_proxyerror(r, HTTP_BAD_GATEWAY, resp));
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: connected.");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: connected.");
 
     ap_bvputs(ctrl, "USER ", user, CRLF, NULL);
-    ap_bflush(ctrl);                        /* capture any errors */
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: USER %s", user);
+    ap_bflush(ctrl);            /* capture any errors */
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: USER %s", user);
 
     /* possible results; 230, 331, 332, 421, 500, 501, 530 */
     /* states: 1 - error, 2 - success; 3 - send password, 4,5 fail */
@@ -776,19 +780,19 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     /* 332 Need account for login. */
     /* 421 Service not available, closing control connection. */
     /* 500 Syntax error, command unrecognized. */
-    /*     (This may include errors such as command line too long.) */
+    /* (This may include errors such as command line too long.) */
     /* 501 Syntax error in parameters or arguments. */
     /* 530 Not logged in. */
     i = ftp_getrc(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
     if (i == -1 || i == 421) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                    "Error reading from remote server"));
+                                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
     }
     if (i == 530) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                      ftp_unauthorized (r, 1));
+                                      ftp_unauthorized(r, 1));
     }
     if (i != 230 && i != 331) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
@@ -798,50 +802,51 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     if (i == 331) {             /* send password */
         if (password == NULL) {
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                          ftp_unauthorized (r, 0));
+                                          ftp_unauthorized(r, 0));
         }
         ap_bvputs(ctrl, "PASS ", password, CRLF, NULL);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PASS %s", password);
-    /* possible results 202, 230, 332, 421, 500, 501, 503, 530 */
-    /* 230 User logged in, proceed. */
-    /* 332 Need account for login. */
-    /* 421 Service not available, closing control connection. */
-    /* 500 Syntax error, command unrecognized. */
-    /* 501 Syntax error in parameters or arguments. */
-    /* 503 Bad sequence of commands. */
-    /* 530 Not logged in. */
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PASS %s", password);
+        /* possible results 202, 230, 332, 421, 500, 501, 503, 530 */
+        /* 230 User logged in, proceed. */
+        /* 332 Need account for login. */
+        /* 421 Service not available, closing control connection. */
+        /* 500 Syntax error, command unrecognized. */
+        /* 501 Syntax error in parameters or arguments. */
+        /* 503 Bad sequence of commands. */
+        /* 530 Not logged in. */
         i = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
         if (i == -1 || i == 421) {
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                    "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
         }
         if (i == 332) {
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_UNAUTHORIZED,
-                                 "Need account for login"));
+                                          ap_proxyerror(r, HTTP_UNAUTHORIZED,
+                                                 "Need account for login"));
         }
         /* @@@ questionable -- we might as well return a 403 Forbidden here */
-        if (i == 530) /* log it: passwd guessing attempt? */
+        if (i == 530)           /* log it: passwd guessing attempt? */
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                          ftp_unauthorized (r, 1));
+                                          ftp_unauthorized(r, 1));
         if (i != 230 && i != 202)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_BAD_GATEWAY);
     }
 
-    /* Special handling for leading "%2f": this enforces a "cwd /"
-     * out of the $HOME directory which was the starting point after login
+    /*
+     * Special handling for leading "%2f": this enforces a "cwd /" out of the
+     * $HOME directory which was the starting point after login
      */
     if (strncasecmp(path, "%2f", 3) == 0) {
         path += 3;
-        while (*path == '/') /* skip leading '/' (after root %2f) */
+        while (*path == '/')    /* skip leading '/' (after root %2f) */
             ++path;
         ap_bputs("CWD /" CRLF, ctrl);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: CWD /");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: CWD /");
 
         /* possible results: 250, 421, 500, 501, 502, 530, 550 */
         /* 250 Requested file action okay, completed. */
@@ -852,11 +857,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         /* 530 Not logged in. */
         /* 550 Requested action not taken. */
         i = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
         if (i == -1 || i == 421)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                        ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
         else if (i == 550)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_NOT_FOUND);
@@ -869,7 +874,7 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
  * this is what we must do if we don't know the OS type of the remote
  * machine
  */
-    for ( ; (strp = strchr(path, '/')) != NULL ; path = strp + 1) {
+    for (; (strp = strchr(path, '/')) != NULL; path = strp + 1) {
         char *slash = strp;
 
         *slash = '\0';
@@ -880,38 +885,38 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         if (strp[1] == '\0')
             break;
 
-        len = decodeenc(path); /* Note! This decodes a %2f -> "/" */
-        if (strchr(path, '/')) /* were there any '/' characters? */
+        len = decodeenc(path);  /* Note! This decodes a %2f -> "/" */
+        if (strchr(path, '/'))  /* were there any '/' characters? */
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                        ap_proxyerror(r, HTTP_BAD_REQUEST,
-                                      "Use of %2F is only allowed at the base directory"));
+                                          ap_proxyerror(r, HTTP_BAD_REQUEST,
+                       "Use of %2F is only allowed at the base directory"));
 
         ap_bvputs(ctrl, "CWD ", path, CRLF, NULL);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
         *slash = '/';
 
 /* responses: 250, 421, 500, 501, 502, 530, 550 */
-    /* 250 Requested file action okay, completed. */
-    /* 421 Service not available, closing control connection. */
-    /* 500 Syntax error, command unrecognized. */
-    /* 501 Syntax error in parameters or arguments. */
-    /* 502 Command not implemented. */
-    /* 530 Not logged in. */
-    /* 550 Requested action not taken. */
+        /* 250 Requested file action okay, completed. */
+        /* 421 Service not available, closing control connection. */
+        /* 500 Syntax error, command unrecognized. */
+        /* 501 Syntax error in parameters or arguments. */
+        /* 502 Command not implemented. */
+        /* 530 Not logged in. */
+        /* 550 Requested action not taken. */
         i = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
         if (i == -1 || i == 421)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                    "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
         if (i == 550)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_NOT_FOUND);
         if (i == 500 || i == 501)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_BAD_REQUEST,
-                                    "Syntax error in filename (reported by ftp server)"));
+                                          ap_proxyerror(r, HTTP_BAD_REQUEST,
+                      "Syntax error in filename (reported by ftp server)"));
         if (i != 250)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_BAD_GATEWAY);
@@ -919,18 +924,19 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 
     if (parms != NULL && strncmp(parms, "type=", 5) == 0
         && ap_isalpha(parms[5])) {
-        /* "type=d" forces a dir listing.
-         * The other types (i|a|e) are directly used for the ftp TYPE command
+        /*
+         * "type=d" forces a dir listing. The other types (i|a|e) are
+         * directly used for the ftp TYPE command
          */
-        if ( ! (get_dirlisting = (parms[5] == 'd')))
+        if (!(get_dirlisting = (parms[5] == 'd')))
             xfer_type = ap_toupper(parms[5]);
 
         /* Check valid types, rather than ignoring invalid types silently: */
         if (strchr("AEI", xfer_type) == NULL)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                       ap_proxyerror(r, HTTP_BAD_REQUEST, ap_pstrcat(r->pool,
-                                    "ftp proxy supports only types 'a', 'i', or 'e': \"",
-                                    parms, "\" is invalid.", NULL)));
+                       "ftp proxy supports only types 'a', 'i', or 'e': \"",
+                                           parms, "\" is invalid.", NULL)));
     }
     else {
         /* make binary transfers the default */
@@ -941,23 +947,23 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     dsock = ap_psocket(p, PF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (dsock == -1) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
-                                    "proxy: error creating PASV socket"));
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
+                                      "proxy: error creating PASV socket"));
     }
 
 #if !defined (TPF) && !defined(BEOS)
     if (conf->recv_buffer_size) {
         if (setsockopt(dsock, SOL_SOCKET, SO_RCVBUF,
-               (const char *) &conf->recv_buffer_size, sizeof(int)) == -1) {
+                (const char *)&conf->recv_buffer_size, sizeof(int)) == -1) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                         "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
+                          "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
         }
     }
 #endif
 
     ap_bputs("PASV" CRLF, ctrl);
     ap_bflush(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PASV command issued");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PASV command issued");
 /* possible results: 227, 421, 500, 501, 502, 530 */
     /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2). */
     /* 421 Service not available, closing control connection. */
@@ -969,19 +975,19 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     i = ap_bgets(pasv, sizeof(pasv), ctrl);
     if (i == -1 || i == 421) {
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
-                                    "proxy: PASV: control connection is toast"));
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
+                               "proxy: PASV: control connection is toast"));
     }
     else {
         pasv[i - 1] = '\0';
-        pstr = strtok(pasv, " ");        /* separate result code */
+        pstr = strtok(pasv, " ");       /* separate result code */
         if (pstr != NULL) {
             presult = atoi(pstr);
             if (*(pstr + strlen(pstr) + 1) == '=')
                 pstr += strlen(pstr) + 2;
-            else
-            {
-                pstr = strtok(NULL, "(");  /* separate address & port params */
+            else {
+                pstr = strtok(NULL, "(");       /* separate address & port
+                                                 * params */
                 if (pstr != NULL)
                     pstr = strtok(NULL, ")");
             }
@@ -989,15 +995,15 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         else
             presult = atoi(pasv);
 
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", presult);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", presult);
 
         if (presult == 227 && pstr != NULL && (sscanf(pstr,
                  "%d,%d,%d,%d,%d,%d", &h3, &h2, &h1, &h0, &p1, &p0) == 6)) {
             /* pardon the parens, but it makes gcc happy */
             paddr = (((((h3 << 8) + h2) << 8) + h1) << 8) + h0;
             pport = (p1 << 8) + p0;
-            ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: contacting host %d.%d.%d.%d:%d",
-                     h3, h2, h1, h0, pport);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: contacting host %d.%d.%d.%d:%d",
+                         h3, h2, h1, h0, pport);
             data_addr.sin_family = AF_INET;
             data_addr.sin_addr.s_addr = htonl(paddr);
             data_addr.sin_port = htons(pport);
@@ -1005,10 +1011,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 
             if (i == -1) {
                 return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                             ap_pstrcat(r->pool,
-                                        "Could not connect to remote machine: ",
-                                        strerror(errno), NULL)));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                                        ap_pstrcat(r->pool,
+                                    "Could not connect to remote machine: ",
+                                                   strerror(errno), NULL)));
             }
             pasvmode = 1;
         }
@@ -1020,45 +1026,45 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 
     if (!pasvmode) {            /* set up data connection */
         clen = sizeof(struct sockaddr_in);
-        if (getsockname(sock, (struct sockaddr *) &server, &clen) < 0) {
+        if (getsockname(sock, (struct sockaddr *)&server, &clen) < 0) {
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
                                     "proxy: error getting socket address"));
         }
 
         dsock = ap_psocket(p, PF_INET, SOCK_STREAM, IPPROTO_TCP);
         if (dsock == -1) {
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
-                                    "proxy: error creating socket"));
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
+                                           "proxy: error creating socket"));
         }
 
-        if (setsockopt(dsock, SOL_SOCKET, SO_REUSEADDR, (void *) &one,
+        if (setsockopt(dsock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
                        sizeof(one)) == -1) {
-#ifndef _OSD_POSIX /* BS2000 has this option "always on" */
+#ifndef _OSD_POSIX              /* BS2000 has this option "always on" */
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
-                                    "proxy: error setting reuseaddr option"));
-#endif /*_OSD_POSIX*/
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
+                                  "proxy: error setting reuseaddr option"));
+#endif                          /* _OSD_POSIX */
         }
 
-        if (bind(dsock, (struct sockaddr *) &server,
+        if (bind(dsock, (struct sockaddr *)&server,
                  sizeof(struct sockaddr_in)) == -1) {
 
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                      ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, 
-                        ap_psprintf(p, "proxy: error binding to ftp data socket %s:%d",
-                           inet_ntoa(server.sin_addr), server.sin_port)));
+                                ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR,
+             ap_psprintf(p, "proxy: error binding to ftp data socket %s:%d",
+                         inet_ntoa(server.sin_addr), server.sin_port)));
         }
-        listen(dsock, 2);        /* only need a short queue */
+        listen(dsock, 2);       /* only need a short queue */
     }
 
 /* set request; "path" holds last path component */
     len = decodeenc(path);
-    if (strchr(path, '/')) /* were there any '/' characters? */
+    if (strchr(path, '/'))      /* were there any '/' characters? */
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                    ap_proxyerror(r, HTTP_BAD_REQUEST,
-                                  "Use of %2F is only allowed at the base directory"));
+                                      ap_proxyerror(r, HTTP_BAD_REQUEST,
+                       "Use of %2F is only allowed at the base directory"));
 
     /* TM - if len == 0 then it must be a directory (you can't RETR nothing) */
 
@@ -1068,16 +1074,16 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     else {
         ap_bvputs(ctrl, "SIZE ", path, CRLF, NULL);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: SIZE %s", path);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: SIZE %s", path);
         i = ftp_getrc_msg(ctrl, resp, sizeof resp);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d with response %s", i, resp);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d with response %s", i, resp);
         if (i != 500) {         /* Size command not recognized */
             if (i == 550) {     /* Not a regular file */
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: SIZE shows this is a directory");
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: SIZE shows this is a directory");
                 get_dirlisting = 1;
                 ap_bvputs(ctrl, "CWD ", path, CRLF, NULL);
                 ap_bflush(ctrl);
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
 
                 /* possible results: 250, 421, 500, 501, 502, 530, 550 */
                 /* 250 Requested file action okay, completed. */
@@ -1088,11 +1094,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
                 /* 530 Not logged in. */
                 /* 550 Requested action not taken. */
                 i = ftp_getrc(ctrl);
-                ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+                ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
                 if (i == -1 || i == 421)
                     return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                              "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
                 if (i == 550)
                     return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                                   HTTP_NOT_FOUND);
@@ -1102,9 +1108,8 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
                 path = "";
                 len = 0;
             }
-            else if (i == 213) { /* Size command ok */
-                for (j = 0; j < sizeof resp && ap_isdigit(resp[j]); j++)
-                        ;
+            else if (i == 213) {/* Size command ok */
+                for (j = 0; j < sizeof resp && ap_isdigit(resp[j]); j++);
                 resp[j] = '\0';
                 if (resp[0] != '\0')
                     size = ap_pstrdup(p, resp);
@@ -1115,7 +1120,7 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 #ifdef AUTODETECT_PWD
     ap_bvputs(ctrl, "PWD", CRLF, NULL);
     ap_bflush(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PWD");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PWD");
 /* responses: 257, 500, 501, 502, 421, 550 */
     /* 257 "<directory-name>" <commentary> */
     /* 421 Service not available, closing control connection. */
@@ -1124,11 +1129,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     /* 502 Command not implemented. */
     /* 550 Requested action not taken. */
     i = ftp_getrc_msg(ctrl, resp, sizeof resp);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PWD returned status %d", i);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PWD returned status %d", i);
     if (i == -1 || i == 421)
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
     if (i == 550)
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                       HTTP_NOT_FOUND);
@@ -1136,19 +1141,19 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         const char *dirp = resp;
         cwd = ap_getword_conf(r->pool, &dirp);
     }
-#endif /*AUTODETECT_PWD*/
+#endif                          /* AUTODETECT_PWD */
 
     if (get_dirlisting) {
         if (len != 0)
             ap_bvputs(ctrl, "LIST ", path, CRLF, NULL);
         else
             ap_bputs("LIST -lag" CRLF, ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: LIST %s", (len == 0 ? "" : path));
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: LIST %s", (len == 0 ? "" : path));
     }
     else {
         ftp_set_TYPE(r, ctrl, xfer_type);
         ap_bvputs(ctrl, "RETR ", path, CRLF, NULL);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: RETR %s", path);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: RETR %s", path);
     }
     ap_bflush(ctrl);
 /* RETR: 110, 125, 150, 226, 250, 421, 425, 426, 450, 451, 500, 501, 530, 550
@@ -1168,19 +1173,20 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     /* 530 Not logged in. */
     /* 550 Requested action not taken. */
     rc = ftp_getrc(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
     if (rc == -1 || rc == 421)
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                      ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
     if (rc == 550) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: RETR failed, trying LIST instead");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: RETR failed, trying LIST instead");
         get_dirlisting = 1;
-        ftp_set_TYPE(r, ctrl, 'A'); /* directories must be transferred in ASCII */
+        ftp_set_TYPE(r, ctrl, 'A');     /* directories must be transferred in
+                                         * ASCII */
 
         ap_bvputs(ctrl, "CWD ", path, CRLF, NULL);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: CWD %s", path);
         /* possible results: 250, 421, 500, 501, 502, 530, 550 */
         /* 250 Requested file action okay, completed. */
         /* 421 Service not available, closing control connection. */
@@ -1190,11 +1196,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         /* 530 Not logged in. */
         /* 550 Requested action not taken. */
         rc = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
         if (rc == -1 || rc == 421)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
         if (rc == 550)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_NOT_FOUND);
@@ -1205,7 +1211,7 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 #ifdef AUTODETECT_PWD
         ap_bvputs(ctrl, "PWD", CRLF, NULL);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PWD");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PWD");
 /* responses: 257, 500, 501, 502, 421, 550 */
         /* 257 "<directory-name>" <commentary> */
         /* 421 Service not available, closing control connection. */
@@ -1214,11 +1220,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         /* 502 Command not implemented. */
         /* 550 Requested action not taken. */
         i = ftp_getrc_msg(ctrl, resp, sizeof resp);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: PWD returned status %d", i);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: PWD returned status %d", i);
         if (i == -1 || i == 421)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
         if (i == 550)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
                                           HTTP_NOT_FOUND);
@@ -1226,22 +1232,22 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
             const char *dirp = resp;
             cwd = ap_getword_conf(r->pool, &dirp);
         }
-#endif /*AUTODETECT_PWD*/
+#endif                          /* AUTODETECT_PWD */
 
         ap_bputs("LIST -lag" CRLF, ctrl);
         ap_bflush(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: LIST -lag");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: LIST -lag");
         rc = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", rc);
         if (rc == -1 || rc == 421)
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                ap_proxyerror(r, HTTP_BAD_GATEWAY,
-                                      "Error reading from remote server"));
+                                          ap_proxyerror(r, HTTP_BAD_GATEWAY,
+                                       "Error reading from remote server"));
     }
     ap_kill_timeout(r);
     if (rc != 125 && rc != 150 && rc != 226 && rc != 250)
         return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
-                                          HTTP_BAD_GATEWAY);
+                                      HTTP_BAD_GATEWAY);
 
     r->status = HTTP_OK;
     r->status_line = "200 OK";
@@ -1260,11 +1266,12 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     }
     else {
 #ifdef CHARSET_EBCDIC
-        r->ebcdic.conv_out = 0; /* do not convert what we read from the ftp server */
+        r->ebcdic.conv_out = 0; /* do not convert what we read from the ftp
+                                 * server */
 #endif
         if (r->content_type != NULL) {
             ap_table_setn(resp_hdrs, "Content-Type", r->content_type);
-            ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: Content-Type set to %s", r->content_type);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: Content-Type set to %s", r->content_type);
         }
         else {
             ap_table_setn(resp_hdrs, "Content-Type", ap_default_type(r));
@@ -1272,11 +1279,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         if (xfer_type != 'A' && size != NULL) {
             /* We "trust" the ftp server to really serve (size) bytes... */
             ap_table_set(resp_hdrs, "Content-Length", size);
-            ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: Content-Length set to %s", size);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: Content-Length set to %s", size);
         }
     }
     if (r->content_encoding != NULL && r->content_encoding[0] != '\0') {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: Content-Encoding set to %s", r->content_encoding);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: Content-Encoding set to %s", r->content_encoding);
         ap_table_setn(resp_hdrs, "Content-Encoding", r->content_encoding);
     }
 
@@ -1285,10 +1292,10 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         for (i = 0; i < conf->nocaches->nelts; i++) {
             if (destaddr.s_addr == ncent[i].addr.s_addr ||
                 (ncent[i].name != NULL &&
-                  (ncent[i].name[0] == '*' ||
-                   strstr(host, ncent[i].name) != NULL))) {
-               nocache = 1;
-               break;
+                 (ncent[i].name[0] == '*' ||
+                  strstr(host, ncent[i].name) != NULL))) {
+                nocache = 1;
+                break;
             }
         }
     }
@@ -1303,11 +1310,11 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         ap_hard_timeout("proxy ftp data connect", r);
         clen = sizeof(struct sockaddr_in);
         do
-            csd = accept(dsock, (struct sockaddr *) &server, &clen);
+            csd = accept(dsock, (struct sockaddr *)&server, &clen);
         while (csd == -1 && errno == EINTR);
         if (csd == -1) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                         "proxy: failed to accept data connection");
+                          "proxy: failed to accept data connection");
             if (c != NULL)
                 c = ap_proxy_cache_error(c);
             return ftp_cleanup_and_return(r, ctrl, data, sock, dsock,
@@ -1327,15 +1334,15 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
     /* send response */
     /* write status line and headers to the cache file */
     ap_proxy_write_headers(c, ap_pstrcat(p, "HTTP/1.1 ", r->status_line, NULL), resp_hdrs);
-    
+
     /* Setup the headers for our client from upstreams response-headers */
     ap_overlap_tables(r->headers_out, resp_hdrs, AP_OVERLAP_TABLES_SET);
     /* Add X-Cache header */
     ap_table_setn(r->headers_out, "X-Cache",
                   ap_pstrcat(r->pool, "MISS from ",
-                             ap_get_server_name(r), NULL)); 
+                             ap_get_server_name(r), NULL));
     /* The Content-Type of this response is the upstream one. */
-    r->content_type = ap_table_get (r->headers_out, "Content-Type");
+    r->content_type = ap_table_get(r->headers_out, "Content-Type");
     /* finally output the headers to the client */
     ap_send_http_header(r);
 
@@ -1357,8 +1364,9 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
         data = NULL;
         dsock = -1;
 
-        /* We checked for 125||150||226||250 above.
-         * See if another rc is pending, and fetch it:
+        /*
+         * We checked for 125||150||226||250 above. See if another rc is
+         * pending, and fetch it:
          */
         if (rc == 125 || rc == 150)
             rc = ftp_getrc(ctrl);
@@ -1372,16 +1380,16 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
             data = NULL;
             dsock = -1;
         }
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: ABOR");
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: ABOR");
 /* responses: 225, 226, 421, 500, 501, 502 */
-    /* 225 Data connection open; no transfer in progress. */
-    /* 226 Closing data connection. */
-    /* 421 Service not available, closing control connection. */
-    /* 500 Syntax error, command unrecognized. */
-    /* 501 Syntax error in parameters or arguments. */
-    /* 502 Command not implemented. */
+        /* 225 Data connection open; no transfer in progress. */
+        /* 226 Closing data connection. */
+        /* 421 Service not available, closing control connection. */
+        /* 500 Syntax error, command unrecognized. */
+        /* 501 Syntax error in parameters or arguments. */
+        /* 502 Command not implemented. */
         i = ftp_getrc(ctrl);
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
+        ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: returned status %d", i);
     }
 
     ap_kill_timeout(r);
@@ -1390,16 +1398,16 @@ int ap_proxy_ftp_handler(request_rec *r, cache_req *c, char *url)
 /* finish */
     ap_bputs("QUIT" CRLF, ctrl);
     ap_bflush(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: QUIT");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: QUIT");
 /* responses: 221, 500 */
     /* 221 Service closing control connection. */
     /* 500 Syntax error, command unrecognized. */
     i = ftp_getrc(ctrl);
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "FTP: QUIT: status %d", i);
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "FTP: QUIT: status %d", i);
 
     ap_bclose(ctrl);
 
-    ap_rflush(r);        /* flush before garbage collection */
+    ap_rflush(r);               /* flush before garbage collection */
 
     ap_proxy_garbage_coll(r);
 
index 5a06a61b30ab1df80575598cea2027d25ffd33e4..04eff05e8ed6fd5ab43b68e8804923cec84cac54 100644 (file)
@@ -76,8 +76,8 @@ int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, int def_p
     const char *err;
     int port;
 
-    /* do syntatic check.
-     * We break the URL into host, port, path, search
+    /*
+     * do syntatic check. We break the URL into host, port, path, search
      */
     port = def_port;
     err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
@@ -85,9 +85,10 @@ int ap_proxy_http_canon(request_rec *r, char *url, const char *scheme, int def_p
         return HTTP_BAD_REQUEST;
 
     /* now parse path/search args, according to rfc1738 */
-    /* N.B. if this isn't a true proxy request, then the URL _path_
-     * has already been decoded.  True proxy requests have r->uri
-     * == r->unparsed_uri, and no others have that property.
+    /*
+     * N.B. if this isn't a true proxy request, then the URL _path_ has
+     * already been decoded.  True proxy requests have r->uri ==
+     * r->unparsed_uri, and no others have that property.
      */
     if (r->uri == r->unparsed_uri) {
         search = strchr(url, '?');
@@ -146,7 +147,7 @@ static const char *proxy_location_reverse_map(request_rec *r, const char *url)
  * route.)
  */
 int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
-                       const char *proxyhost, int proxyport)
+                              const char *proxyhost, int proxyport)
 {
     const char *strp;
     char *strp2;
@@ -169,12 +170,13 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
 
     void *sconf = r->server->module_config;
     proxy_server_conf *conf =
-    (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
+    (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
     struct noproxy_entry *npent = (struct noproxy_entry *) conf->noproxies->elts;
     struct nocache_entry *ncent = (struct nocache_entry *) conf->nocaches->elts;
     int nocache = 0;
 
-    if (conf->cache.root == NULL) nocache = 1;
+    if (conf->cache.root == NULL)
+        nocache = 1;
 
     memset(&server, '\0', sizeof(server));
     server.sin_family = AF_INET;
@@ -213,7 +215,7 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     for (i = 0; i < conf->noproxies->nelts; i++) {
         if (destaddr.s_addr == npent[i].addr.s_addr ||
             (npent[i].name != NULL &&
-              (npent[i].name[0] == '*' || strstr(desthost, npent[i].name) != NULL)))
+             (npent[i].name[0] == '*' || strstr(desthost, npent[i].name) != NULL)))
             return ap_proxyerror(r, HTTP_FORBIDDEN,
                                  "Connect to remote machine blocked");
     }
@@ -232,30 +234,31 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     }
 
 
-    /* we have worked out who exactly we are going to connect to, now
-     * make that connection...
+    /*
+     * we have worked out who exactly we are going to connect to, now make
+     * that connection...
      */
     sock = ap_psocket(p, PF_INET, SOCK_STREAM, IPPROTO_TCP);
     if (sock == -1) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                    "proxy: error creating socket");
+                      "proxy: error creating socket");
         return HTTP_INTERNAL_SERVER_ERROR;
     }
 
 #if !defined(TPF) && !defined(BEOS)
     if (conf->recv_buffer_size) {
         if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
-                       (const char *) &conf->recv_buffer_size, sizeof(int))
+                       (const char *)&conf->recv_buffer_size, sizeof(int))
             == -1) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                         "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
+                          "setsockopt(SO_RCVBUF): Failed to set ProxyReceiveBufferSize, using default");
         }
     }
 #endif
 
 #ifdef SINIX_D_RESOLVER_BUG
     {
-        struct in_addr *ip_addr = (struct in_addr *) *server_hp.h_addr_list;
+        struct in_addr *ip_addr = (struct in_addr *)*server_hp.h_addr_list;
 
         for (; ip_addr->s_addr != 0; ++ip_addr) {
             memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
@@ -280,30 +283,31 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
             return DECLINED;    /* try again another way */
         else
             return ap_proxyerror(r, HTTP_BAD_GATEWAY, ap_pstrcat(r->pool,
-                                "Could not connect to remote machine: ",
-                                strerror(errno), NULL));
+                                    "Could not connect to remote machine: ",
+                                                    strerror(errno), NULL));
     }
 
     /* record request_time for HTTP/1.1 age calculation */
     c->req_time = time(NULL);
 
-    /* build upstream-request headers by stripping r->headers_in from
-     * connection specific headers.
-     * We must not remove the Connection: header from r->headers_in,
-     * we still have to react to Connection: close
+    /*
+     * build upstream-request headers by stripping r->headers_in from
+     * connection specific headers. We must not remove the Connection: header
+     * from r->headers_in, we still have to react to Connection: close
      */
     req_hdrs = ap_copy_table(r->pool, r->headers_in);
     ap_proxy_clear_connection(r->pool, req_hdrs);
 
-    /* At this point, we start sending the HTTP/1.1 request to the
-     * remote server (proxy or otherwise).
+    /*
+     * At this point, we start sending the HTTP/1.1 request to the remote
+     * server (proxy or otherwise).
      */
     f = ap_bcreate(p, B_RDWR | B_SOCKET);
     ap_bpushfd(f, sock, sock);
 
     ap_hard_timeout("proxy send", r);
     ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.1" CRLF,
-           NULL);
+              NULL);
     /* Send Host: now, adding it to req_hdrs wouldn't be much better */
     if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
         ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL);
@@ -313,60 +317,65 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     if (conf->viaopt == via_block) {
         /* Block all outgoing Via: headers */
         ap_table_unset(req_hdrs, "Via");
-    } else if (conf->viaopt != via_off) {
+    }
+    else if (conf->viaopt != via_off) {
         /* Create a "Via:" request header entry and merge it */
         i = ap_get_server_port(r);
-        if (ap_is_default_port(i,r)) {
-            strcpy(portstr,"");
-        } else {
+        if (ap_is_default_port(i, r)) {
+            strcpy(portstr, "");
+        }
+        else {
             ap_snprintf(portstr, sizeof portstr, ":%d", i);
         }
         /* Generate outgoing Via: header with/without server comment: */
         ap_table_mergen(req_hdrs, "Via",
-                    (conf->viaopt == via_full)
+                        (conf->viaopt == via_full)
                         ? ap_psprintf(p, "%d.%d %s%s (%s)",
-                                HTTP_VERSION_MAJOR(r->proto_num),
-                                HTTP_VERSION_MINOR(r->proto_num),
-                                ap_get_server_name(r), portstr,
-                                SERVER_BASEVERSION)
+                                      HTTP_VERSION_MAJOR(r->proto_num),
+                                      HTTP_VERSION_MINOR(r->proto_num),
+                                      ap_get_server_name(r), portstr,
+                                      SERVER_BASEVERSION)
                         : ap_psprintf(p, "%d.%d %s%s",
-                                HTTP_VERSION_MAJOR(r->proto_num),
-                                HTTP_VERSION_MINOR(r->proto_num),
-                                ap_get_server_name(r), portstr)
-                        );
+                                      HTTP_VERSION_MAJOR(r->proto_num),
+                                      HTTP_VERSION_MINOR(r->proto_num),
+                                      ap_get_server_name(r), portstr)
+            );
     }
 
-    /* Add X-Forwarded-For: so that the upstream has a chance to
-       determine, where the original request came from. */
+    /*
+     * Add X-Forwarded-For: so that the upstream has a chance to determine,
+     * where the original request came from.
+     */
     ap_table_mergen(req_hdrs, "X-Forwarded-For", r->connection->remote_ip);
-    
+
     /* we don't yet support keepalives - but we will soon, I promise! */
     ap_table_set(req_hdrs, "Connection", "close");
 
     reqhdrs_arr = ap_table_elts(req_hdrs);
-    reqhdrs_elts = (table_entry *) reqhdrs_arr->elts;
+    reqhdrs_elts = (table_entry *)reqhdrs_arr->elts;
     for (i = 0; i < reqhdrs_arr->nelts; i++) {
         if (reqhdrs_elts[i].key == NULL || reqhdrs_elts[i].val == NULL
 
-        /* Clear out hop-by-hop request headers not to send:
-         * RFC2616 13.5.1 says we should strip these headers:
+        /*
+         * Clear out hop-by-hop request headers not to send: RFC2616 13.5.1
+         * says we should strip these headers:
          */
             || !strcasecmp(reqhdrs_elts[i].key, "Host") /* Already sent */
-            || !strcasecmp(reqhdrs_elts[i].key, "Keep-Alive")
+            ||!strcasecmp(reqhdrs_elts[i].key, "Keep-Alive")
             || !strcasecmp(reqhdrs_elts[i].key, "TE")
             || !strcasecmp(reqhdrs_elts[i].key, "Trailer")
             || !strcasecmp(reqhdrs_elts[i].key, "Transfer-Encoding")
             || !strcasecmp(reqhdrs_elts[i].key, "Upgrade")
-
-            /* XXX: @@@ FIXME: "Proxy-Authorization" should *only* be 
-             * suppressed if THIS server requested the authentication,
-             * not when a frontend proxy requested it!
-             *
-             * The solution to this problem is probably to strip out
-             * the Proxy-Authorisation header in the authorisation
-             * code itself, not here. This saves us having to signal
-             * somehow whether this request was authenticated or not.
-             */
+        /*
+         * XXX: @@@ FIXME: "Proxy-Authorization" should *only* be suppressed
+         * if THIS server requested the authentication, not when a frontend
+         * proxy requested it!
+         * 
+         * The solution to this problem is probably to strip out the
+         * Proxy-Authorisation header in the authorisation code itself, not
+         * here. This saves us having to signal somehow whether this request
+         * was authenticated or not.
+         */
             || !strcasecmp(reqhdrs_elts[i].key, "Proxy-Authorization"))
             continue;
         ap_bvputs(f, reqhdrs_elts[i].key, ": ", reqhdrs_elts[i].val, CRLF, NULL);
@@ -384,7 +393,8 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     ap_kill_timeout(r);
 
 
-    /* Right - now it's time to listen for a response.
+    /*
+     * Right - now it's time to listen for a response.
      */
     ap_hard_timeout("proxy receive", r);
 
@@ -393,20 +403,21 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
         ap_bclose(f);
         ap_kill_timeout(r);
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                     "ap_bgets() - proxy receive - Error reading from remote server %s (length %d)",
-                     proxyhost ? proxyhost : desthost, len);
+                      "ap_bgets() - proxy receive - Error reading from remote server %s (length %d)",
+                      proxyhost ? proxyhost : desthost, len);
         return ap_proxyerror(r, HTTP_BAD_GATEWAY,
                              "Error reading from remote server");
-    } else if (len == 0) {
+    }
+    else if (len == 0) {
         ap_bclose(f);
         ap_kill_timeout(r);
         return ap_proxyerror(r, HTTP_BAD_GATEWAY,
                              "Document contains no data");
     }
 
-    /* Is it an HTTP/1 response?
-     * Do some sanity checks on the response.
-     * (This is buggy if we ever see an HTTP/1.10)
+    /*
+     * Is it an HTTP/1 response? Do some sanity checks on the response. (This
+     * is buggy if we ever see an HTTP/1.10)
      */
     if (ap_checkmask(buffer, "HTTP/#.# ###*")) {
         int major, minor;
@@ -436,39 +447,40 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
 
         resp_hdrs = ap_proxy_read_headers(r, buffer, HUGE_STRING_LEN, f);
         if (resp_hdrs == NULL) {
-            ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, r->server,
-                 "proxy: Bad HTTP/%d.%d header returned by %s (%s)",
-                 major, minor, r->uri, r->method);
+            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, r->server,
+                         "proxy: Bad HTTP/%d.%d header returned by %s (%s)",
+                         major, minor, r->uri, r->method);
             resp_hdrs = ap_make_table(p, 20);
-            nocache = 1;    /* do not cache this broken file */
+            nocache = 1;        /* do not cache this broken file */
         }
 
         /* handle Via header in the response */
         if (conf->viaopt != via_off && conf->viaopt != via_block) {
             /* Create a "Via:" response header entry and merge it */
             i = ap_get_server_port(r);
-            if (ap_is_default_port(i,r)) {
-                strcpy(portstr,"");
-            } else {
+            if (ap_is_default_port(i, r)) {
+                strcpy(portstr, "");
+            }
+            else {
                 ap_snprintf(portstr, sizeof portstr, ":%d", i);
             }
             ap_table_mergen((table *)resp_hdrs, "Via",
                             (conf->viaopt == via_full)
                             ? ap_psprintf(p, "%d.%d %s%s (%s)",
-                                major, minor,
-                                ap_get_server_name(r), portstr,
-                                SERVER_BASEVERSION)
+                                          major, minor,
+                                          ap_get_server_name(r), portstr,
+                                          SERVER_BASEVERSION)
                             : ap_psprintf(p, "%d.%d %s%s",
-                                major, minor,
-                                ap_get_server_name(r), portstr)
-                            );
+                                          major, minor,
+                                          ap_get_server_name(r), portstr)
+                );
         }
 
         /* strip hop-by-hop headers defined by Connection */
         ap_proxy_clear_connection(p, resp_hdrs);
         /* Now add out bound headers set by other modules */
         resp_hdrs = ap_overlay_tables(r->pool, r->err_headers_out, resp_hdrs);
-}
+    }
     else {
         /* an http/0.9 response */
         backasswards = 1;
@@ -482,10 +494,11 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     ap_kill_timeout(r);
 
     /*
-     * HTTP/1.1 requires us to accept 3 types of dates, but only generate
-     * one type
+     * HTTP/1.1 requires us to accept 3 types of dates, but only generate one
+     * type
      */
-    /* we SET the dates here, obliterating possible multiple dates, as only
+    /*
+     * we SET the dates here, obliterating possible multiple dates, as only
      * one of each date makes sense in each response.
      */
     if ((datestr = ap_table_get(resp_hdrs, "Date")) != NULL)
@@ -497,33 +510,34 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
 
     /* handle the ProxyPassReverse mappings */
     if ((urlstr = ap_table_get(resp_hdrs, "Location")) != NULL)
-      ap_table_set(resp_hdrs, "Location", proxy_location_reverse_map(r, urlstr));
+        ap_table_set(resp_hdrs, "Location", proxy_location_reverse_map(r, urlstr));
     if ((urlstr = ap_table_get(resp_hdrs, "URI")) != NULL)
-      ap_table_set(resp_hdrs, "URI", proxy_location_reverse_map(r, urlstr));
+        ap_table_set(resp_hdrs, "URI", proxy_location_reverse_map(r, urlstr));
     if ((urlstr = ap_table_get(resp_hdrs, "Content-Location")) != NULL)
-      ap_table_set(resp_hdrs, "Content-Location", proxy_location_reverse_map(r , urlstr));
+        ap_table_set(resp_hdrs, "Content-Location", proxy_location_reverse_map(r, urlstr));
 
 /* check if NoCache directive on this host */
     if (nocache == 0) {
         for (i = 0; i < conf->nocaches->nelts; i++) {
             if (destaddr.s_addr == ncent[i].addr.s_addr ||
                 (ncent[i].name != NULL &&
-                  (ncent[i].name[0] == '*' ||
-                   strstr(desthost, ncent[i].name) != NULL))) {
-               nocache = 1;
-               break;
+                 (ncent[i].name[0] == '*' ||
+                  strstr(desthost, ncent[i].name) != NULL))) {
+                nocache = 1;
+                break;
             }
         }
 
-    /* update the cache file, possibly even fulfilling the request if
-     * it turns out a conditional allowed us to serve the object from the
-     * cache...
-     */
-    i = ap_proxy_cache_update(c, resp_hdrs, !backasswards, nocache);
-    if (i != DECLINED) {
-        ap_bclose(f);
-        return i;
-    }
+        /*
+         * update the cache file, possibly even fulfilling the request if it
+         * turns out a conditional allowed us to serve the object from the
+         * cache...
+         */
+        i = ap_proxy_cache_update(c, resp_hdrs, !backasswards, nocache);
+        if (i != DECLINED) {
+            ap_bclose(f);
+            return i;
+        }
 
         /* write status line and headers to the cache file */
         ap_proxy_write_headers(c, ap_pstrcat(p, "HTTP/1.1 ", r->status_line, NULL), resp_hdrs);
@@ -533,24 +547,26 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
     ap_overlap_tables(r->headers_out, resp_hdrs, AP_OVERLAP_TABLES_SET);
     /* Add X-Cache header - be careful not to obliterate any upstream headers */
     ap_table_mergen(r->headers_out, "X-Cache",
-                  ap_pstrcat(r->pool, "MISS from ",
-                             ap_get_server_name(r), NULL));
+                    ap_pstrcat(r->pool, "MISS from ",
+                               ap_get_server_name(r), NULL));
     /* The Content-Type of this response is the upstream one. */
-    r->content_type = ap_table_get (r->headers_out, "Content-Type");
-    ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "Content-Type: %s", r->content_type);
+    r->content_type = ap_table_get(r->headers_out, "Content-Type");
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "Content-Type: %s", r->content_type);
 
     /* finally output the headers to the client */
     ap_send_http_header(r);
 
-    /* Is it an HTTP/0.9 respose? If so, send the extra data we read
-       from upstream as the start of the reponse to client */
+    /*
+     * Is it an HTTP/0.9 respose? If so, send the extra data we read from
+     * upstream as the start of the reponse to client
+     */
     if (backasswards) {
         ap_hard_timeout("proxy send assbackward", r);
 
         ap_bwrite(r->connection->client, buffer, len);
         if (c != NULL && c->fp != NULL && ap_bwrite(c->fp, buffer, len) != len) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                "proxy: error writing extra data to %s", c->tempfile);
+                      "proxy: error writing extra data to %s", c->tempfile);
             c = ap_proxy_cache_error(c);
         }
         ap_kill_timeout(r);
@@ -558,11 +574,12 @@ int ap_proxy_http_handler(request_rec *r, cache_req *c, char *url,
 
 
 #ifdef CHARSET_EBCDIC
-    /* What we read/write after the header should not be modified
-     * (i.e., the cache copy is ASCII, not EBCDIC, even for text/html)
+    /*
+     * What we read/write after the header should not be modified (i.e., the
+     * cache copy is ASCII, not EBCDIC, even for text/html)
      */
-    ap_bsetflag(f, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 0);
-    ap_bsetflag(r->connection->client, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 0);
+    ap_bsetflag(f, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 0);
+    ap_bsetflag(r->connection->client, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 0);
 #endif
 
 /* send body */
index 0863019dd7b69d488f422e228dc32c1264185ac7..fd2e68f82ec2c75bb7af03c4e1db881b058a2f69 100644 (file)
@@ -63,7 +63,7 @@
 #include "multithread.h"
 #include "http_log.h"
 #include "util_uri.h"
-#include "util_date.h"  /* get ap_checkmask() decl. */
+#include "util_date.h"          /* get ap_checkmask() decl. */
 
 static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r);
 static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r);
@@ -93,9 +93,9 @@ int ap_proxy_hex2c(const char *x)
     else
         i += ch - ('a' - 10);
     return i;
-#else /*CHARSET_EBCDIC*/
-    return (1 == sscanf(x, "%2x", &i)) ? os_toebcdic[i&0xFF] : 0;
-#endif /*CHARSET_EBCDIC*/
+#else                           /* CHARSET_EBCDIC */
+    return (1 == sscanf(x, "%2x", &i)) ? os_toebcdic[i & 0xFF] : 0;
+#endif                          /* CHARSET_EBCDIC */
 }
 
 void ap_proxy_c2hex(int ch, char *x)
@@ -115,14 +115,14 @@ void ap_proxy_c2hex(int ch, char *x)
         x[2] = ('A' - 10) + i;
     else
         x[2] = '0' + i;
-#else /*CHARSET_EBCDIC*/
-    static const char ntoa[] = { "0123456789ABCDEF" };
+#else                           /* CHARSET_EBCDIC */
+    static const char ntoa[] = {"0123456789ABCDEF"};
     ch = os_toascii[ch & 0xFF];
     x[0] = '%';
-    x[1] = ntoa[(ch>>4)&0x0F];
-    x[2] = ntoa[ch&0x0F];
+    x[1] = ntoa[(ch >> 4) & 0x0F];
+    x[2] = ntoa[ch & 0x0F];
     x[3] = '\0';
-#endif /*CHARSET_EBCDIC*/
+#endif                          /* CHARSET_EBCDIC */
 }
 
 /*
@@ -136,7 +136,7 @@ void ap_proxy_c2hex(int ch, char *x)
  * those which must not be touched.
  */
 char *ap_proxy_canonenc(pool *p, const char *x, int len, enum enctype t,
-                        enum proxyreqtype isenc)
+                             enum proxyreqtype isenc)
 {
     int i, j, ch;
     char *y;
@@ -145,7 +145,7 @@ char *ap_proxy_canonenc(pool *p, const char *x, int len, enum enctype t,
 
 /* N.B. in addition to :@&=, this allows ';' in an http path
  * and '?' in an ftp path -- this may be revised
- * 
+ *
  * Also, it makes a '+' character in a search string reserved, as
  * it may be form-encoded. (Although RFC 1738 doesn't allow this -
  * it only permits ; / ? : @ = & as reserved chars.)
@@ -213,7 +213,7 @@ char *ap_proxy_canonenc(pool *p, const char *x, int len, enum enctype t,
  */
 char *
      ap_proxy_canon_netloc(pool *p, char **const urlp, char **userp,
-                        char **passwordp, char **hostp, int *port)
+                                char **passwordp, char **hostp, int *port)
 {
     int i;
     char *strp, *host, *url = *urlp;
@@ -267,13 +267,14 @@ char *
         /* if (i == 0) the no port was given; keep default */
         if (strp[i] != '\0') {
             return "Bad port number in URL";
-        } else if (i > 0) {
+        }
+        else if (i > 0) {
             *port = atoi(strp);
             if (*port > 65535)
                 return "Port number in URL > 65535";
         }
     }
-    ap_str_tolower(host);                /* DNS names are case-insensitive */
+    ap_str_tolower(host);       /* DNS names are case-insensitive */
     if (*host == '\0')
         return "Missing host in URL";
 /* check hostname syntax */
@@ -299,7 +300,7 @@ char *
     return NULL;
 }
 
-static const char * const lwday[7] =
+static const char *const lwday[7] =
 {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
 
 /*
@@ -391,7 +392,7 @@ static int proxy_getline(char *s, int n, BUFF *in, int fold)
     pos = s;
 
     do {
-        retval = ap_bgets(pos, n, in);     /* retval == -1 if error, 0 if EOF */
+        retval = ap_bgets(pos, n, in);  /* retval == -1 if error, 0 if EOF */
 
         if (retval <= 0)
             return ((retval < 0) && (total == 0)) ? -1 : total;
@@ -410,13 +411,14 @@ static int proxy_getline(char *s, int n, BUFF *in, int fold)
         else
             return total;       /* if not, input line exceeded buffer size */
 
-        /* Continue appending if line folding is desired and
-         * the last line was not empty and we have room in the buffer and
-         * the next line begins with a continuation character.
+        /*
+         * Continue appending if line folding is desired and the last line
+         * was not empty and we have room in the buffer and the next line
+         * begins with a continuation character.
          */
     } while (fold && (retval != 1) && (n > 1)
-                  && (ap_blookc(&next, in) == 1)
-                  && ((next == ' ') || (next == '\t')));
+             && (ap_blookc(&next, in) == 1)
+             && ((next == ' ') || (next == '\t')));
 
     return total;
 }
@@ -446,21 +448,23 @@ table *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF *f)
      * the connection closes (EOF), or we timeout.
      */
     while ((len = proxy_getline(buffer, size, f, 1)) > 0) {
-        
-        if (!(value = strchr(buffer, ':'))) {     /* Find the colon separator */
 
-            /* Buggy MS IIS servers sometimes return invalid headers
-             * (an extra "HTTP/1.0 200, OK" line sprinkled in between
-             * the usual MIME headers). Try to deal with it in a sensible
-             * way, but log the fact.
-             * XXX: The mask check is buggy if we ever see an HTTP/1.10 */
+        if (!(value = strchr(buffer, ':'))) {   /* Find the colon separator */
+
+            /*
+             * Buggy MS IIS servers sometimes return invalid headers (an
+             * extra "HTTP/1.0 200, OK" line sprinkled in between the usual
+             * MIME headers). Try to deal with it in a sensible way, but log
+             * the fact. XXX: The mask check is buggy if we ever see an
+             * HTTP/1.10
+             */
 
             if (!ap_checkmask(buffer, "HTTP/#.# ###*")) {
                 /* Nope, it wasn't even an extra HTTP header. Give up. */
                 return NULL;
             }
 
-            ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, r->server,
+            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, r->server,
                          "proxy: Ignoring duplicate HTTP header "
                          "returned by %s (%s)", r->uri, r->method);
             continue;
@@ -468,26 +472,27 @@ table *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF *f)
 
         *value = '\0';
         ++value;
-        /* XXX: RFC2068 defines only SP and HT as whitespace, this test is
+        /*
+         * XXX: RFC2068 defines only SP and HT as whitespace, this test is
          * wrong... and so are many others probably.
          */
         while (ap_isspace(*value))
             ++value;            /* Skip to start of value   */
 
         /* should strip trailing whitespace as well */
-        for (end = &value[strlen(value)-1]; end > value && ap_isspace(*end); --end)
+        for (end = &value[strlen(value) - 1]; end > value && ap_isspace(*end); --end)
             *end = '\0';
 
         /* make sure we add so as not to destroy duplicated headers */
         ap_table_add(resp_hdrs, buffer, value);
 
         /* the header was too long; at the least we should skip extra data */
-        if (len >= size - 1) { 
+        if (len >= size - 1) {
             while ((len = proxy_getline(field, MAX_STRING_LEN, f, 1))
-                    >= MAX_STRING_LEN - 1) {
+                   >= MAX_STRING_LEN - 1) {
                 /* soak up the extra data */
             }
-            if (len == 0) /* time to exit the larger loop as well */
+            if (len == 0)       /* time to exit the larger loop as well */
                 break;
         }
     }
@@ -501,16 +506,20 @@ table *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF *f)
 
 long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int nowrite, size_t recv_buffer_size)
 {
-    int  ok;
+    int ok;
     char *buf;
     size_t buf_size;
     long total_bytes_rcvd;
     register int n, o, w;
     conn_rec *con = r->connection;
-    int alternate_timeouts = 1; /* 1 if we alternate between soft & hard timeouts */
+    int alternate_timeouts = 1; /* 1 if we alternate between soft & hard
+                                 * timeouts */
 
     /* allocate a buffer to store the bytes in */
-    /* make sure it is at least IOBUFSIZE, as recv_buffer_size may be zero for system default */
+    /*
+     * make sure it is at least IOBUFSIZE, as recv_buffer_size may be zero
+     * for system default
+     */
     buf_size = MAX(recv_buffer_size, IOBUFSIZE);
     buf = ap_palloc(r->pool, buf_size);
 
@@ -520,15 +529,16 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
 
 #ifdef CHARSET_EBCDIC
     /* The cache copy is ASCII, not EBCDIC, even for text/html) */
-    ap_bsetflag(f, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 0);
+    ap_bsetflag(f, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 0);
     if (c != NULL && c->fp != NULL)
-        ap_bsetflag(c->fp, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 0);
-    ap_bsetflag(con->client, B_ASCII2EBCDIC|B_EBCDIC2ASCII, 0);
+        ap_bsetflag(c->fp, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 0);
+    ap_bsetflag(con->client, B_ASCII2EBCDIC | B_EBCDIC2ASCII, 0);
 #endif
 
-    /* Since we are reading from one buffer and writing to another,
-     * it is unsafe to do a soft_timeout here, at least until the proxy
-     * has its own timeout handler which can set both buffers to EOUT.
+    /*
+     * Since we are reading from one buffer and writing to another, it is
+     * unsafe to do a soft_timeout here, at least until the proxy has its own
+     * timeout handler which can set both buffers to EOUT.
      */
 
     ap_kill_timeout(r);
@@ -538,12 +548,13 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
     ap_hard_timeout("proxy send body", r);
     alternate_timeouts = 0;
 #else
-    /* CHECKME! Since hard_timeout won't work in unix on sends with partial
-     * cache completion, we have to alternate between hard_timeout
-     * for reads, and soft_timeout for send.  This is because we need
-     * to get a return from ap_bwrite to be able to continue caching.
-     * BUT, if we *can't* continue anyway, just use hard_timeout.
-     * (Also, if no cache file is written, use hard timeouts)
+    /*
+     * CHECKME! Since hard_timeout won't work in unix on sends with partial
+     * cache completion, we have to alternate between hard_timeout for reads,
+     * and soft_timeout for send.  This is because we need to get a return
+     * from ap_bwrite to be able to continue caching. BUT, if we *can't*
+     * continue anyway, just use hard_timeout. (Also, if no cache file is
+     * written, use hard timeouts)
      */
 
     if (c == NULL || c->len <= 0 || c->cache_completion == 1.0) {
@@ -552,11 +563,12 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
     }
 #endif
 
-    /* Loop and ap_bread() while we can successfully read and write,
-     * or (after the client aborted) while we can successfully
-     * read and finish the configured cache_completion.
+    /*
+     * Loop and ap_bread() while we can successfully read and write, or
+     * (after the client aborted) while we can successfully read and finish
+     * the configured cache_completion.
      */
-    for (ok = 1; ok; ) {
+    for (ok = 1; ok;) {
         if (alternate_timeouts)
             ap_hard_timeout("proxy recv body from upstream server", r);
 
@@ -576,22 +588,23 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
         if (n == -1) {          /* input error */
             if (c != NULL) {
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                    "proxy: error reading from %s", c->url);
+                              "proxy: error reading from %s", c->url);
                 c = ap_proxy_cache_error(c);
             }
             break;
         }
         if (n == 0)
-            break;                /* EOF */
+            break;              /* EOF */
         o = 0;
         total_bytes_rcvd += n;
 
         /* if we've received everything... */
-        /* in the case of slow frontends and expensive backends,
-         * we want to avoid leaving a backend connection hanging
-         * while the frontend takes it's time to absorb the bytes.
-         * so: if we just read the last block, we close the backend
-         * connection now instead of later - it's no longer needed.
+        /*
+         * in the case of slow frontends and expensive backends, we want to
+         * avoid leaving a backend connection hanging while the frontend
+         * takes it's time to absorb the bytes. so: if we just read the last
+         * block, we close the backend connection now instead of later - it's
+         * no longer needed.
          */
         if (total_bytes_rcvd == len) {
             ap_bclose(f);
@@ -599,13 +612,17 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
         }
 
         /* Write to cache first. */
-        /*@@@ XXX FIXME: Assuming that writing the cache file won't time out?!!? */
+        /*
+         * @@@ XXX FIXME: Assuming that writing the cache file won't time
+         * out?!!?
+         */
         if (c != NULL && c->fp != NULL) {
             if (ap_bwrite(c->fp, &buf[0], n) != n) {
                 ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                    "proxy: error writing to %s", c->tempfile);
+                              "proxy: error writing to %s", c->tempfile);
                 c = ap_proxy_cache_error(c);
-            } else {
+            }
+            else {
                 c->written += n;
             }
         }
@@ -624,18 +641,19 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
 
             if (w <= 0) {
                 if (c != NULL) {
-                    /* when a send failure occurs, we need to decide
-                     * whether to continue loading and caching the
-                     * document, or to abort the whole thing
+                    /*
+                     * when a send failure occurs, we need to decide whether
+                     * to continue loading and caching the document, or to
+                     * abort the whole thing
                      */
                     ok = (c->len > 0) &&
-                         (c->cache_completion > 0) &&
-                         (c->len * c->cache_completion < total_bytes_rcvd);
+                        (c->cache_completion > 0) &&
+                        (c->len * c->cache_completion < total_bytes_rcvd);
 
-                    if (! ok) {
-                        if (c->fp!=NULL) {
-                        ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));
-                        c->fp = NULL;
+                    if (!ok) {
+                        if (c->fp != NULL) {
+                            ap_pclosef(c->req->pool, ap_bfileno(c->fp, B_WR));
+                            c->fp = NULL;
                         }
                         unlink(c->tempfile);
                         c = NULL;
@@ -646,13 +664,13 @@ long int ap_proxy_send_fb(BUFF *f, request_rec *r, cache_req *c, off_t len, int
             }
             n -= w;
             o += w;
-        } /* while client alive and more data to send */
+        }                       /* while client alive and more data to send */
 
         /* if we've received everything, leave now */
         if (total_bytes_rcvd == len)
             break;
 
-    } /* loop and ap_bread while "ok" */
+    }                           /* loop and ap_bread while "ok" */
 
     /* if the backend connection is still open, close it */
     if (f) {
@@ -677,11 +695,11 @@ void ap_proxy_write_headers(cache_req *c, const char *respline, table *t)
     /* write status line */
     if (respline && c->fp != NULL &&
         ap_bvputs(c->fp, respline, CRLF, NULL) == -1) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                          "proxy: error writing status line to %s", c->tempfile);
-            c = ap_proxy_cache_error(c);
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
+                      "proxy: error writing status line to %s", c->tempfile);
+        c = ap_proxy_cache_error(c);
         return;
-        }
+    }
 
     /* write response headers to the cache file */
     ap_table_do(ap_proxy_send_hdr_line, c, t, NULL);
@@ -706,7 +724,7 @@ int ap_proxy_liststr(const char *list, const char *key, char **val)
     int len, i;
     const char *p;
     char valbuf[HUGE_STRING_LEN];
-    valbuf[sizeof(valbuf)-1] = 0; /* safety terminating zero */
+    valbuf[sizeof(valbuf) - 1] = 0;     /* safety terminating zero */
 
     len = strlen(key);
 
@@ -734,7 +752,7 @@ int ap_proxy_liststr(const char *list, const char *key, char **val)
                 while (ap_isspace(*list)) {
                     list++;
                 }
-                strncpy(valbuf, list, MIN(p-list, sizeof(valbuf)-1));
+                strncpy(valbuf, list, MIN(p - list, sizeof(valbuf) - 1));
                 *val = valbuf;
             }
             return 1;
@@ -760,7 +778,7 @@ void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength)
     static const char enc_table[32] = "abcdefghijklmnopqrstuvwxyz012345";
 
     ap_MD5Init(&context);
-    ap_MD5Update(&context, (const unsigned char *) it, strlen(it));
+    ap_MD5Update(&context, (const unsigned char *)it, strlen(it));
     ap_MD5Final(digest, &context);
 
 /* encode 128 bits as 26 characters, using a modified uuencoding */
@@ -805,17 +823,19 @@ void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength)
     int i, k, d;
     unsigned int x;
 #if defined(MPE) || (defined(AIX) && defined(__ps2__))
-    /* Believe it or not, AIX 1.x does not allow you to name a file '@',
-     * so hack around it in the encoding. */
+    /*
+     * Believe it or not, AIX 1.x does not allow you to name a file '@', so
+     * hack around it in the encoding.
+     */
     static const char enc_table[64] =
-        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_%";
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_%";
 #else
     static const char enc_table[64] =
-        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
 #endif
 
     ap_MD5Init(&context);
-    ap_MD5Update(&context, (const unsigned char *) it, strlen(it));
+    ap_MD5Update(&context, (const unsigned char *)it, strlen(it));
     ap_MD5Final(digest, &context);
 
 /* encode 128 bits as 22 characters, using a modified uuencoding */
@@ -831,7 +851,7 @@ void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength)
     }
 /* one byte left */
     x = digest[15];
-    tmp[k++] = enc_table[x >> 2];        /* use up 6 bits */
+    tmp[k++] = enc_table[x >> 2];       /* use up 6 bits */
     tmp[k++] = enc_table[(x << 4) & 0x3f];
     /* now split into directory levels */
 
@@ -845,7 +865,7 @@ void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength)
     val[i + 22 - k] = '\0';
 }
 
-#endif /* CASE_BLIND_FILESYSTEM */
+#endif                          /* CASE_BLIND_FILESYSTEM */
 
 /*
  * Converts 16 hex digits to a time integer
@@ -867,9 +887,9 @@ int ap_proxy_hex2sec(const char *x)
     }
 /* no longer necessary, as the source hex is 8-byte int */
 /*    if (j == 0xffffffff)*/
-/*      return -1;*/            /* so that it works with 8-byte ints */
+    /*      return -1;*//* so that it works with 8-byte ints */
 /*    else */
-        return j;
+    return j;
 }
 
 /*
@@ -917,14 +937,14 @@ cache_req *ap_proxy_cache_error(cache_req *c)
 int ap_proxyerror(request_rec *r, int statuscode, const char *message)
 {
     ap_table_setn(r->notes, "error-notes",
-                  ap_pstrcat(r->pool, 
+                  ap_pstrcat(r->pool,
                              "The proxy server could not handle the request "
-                             "<EM><A HREF=\"", ap_escape_uri(r->pool, r->uri),
+                           "<EM><A HREF=\"", ap_escape_uri(r->pool, r->uri),
                              "\">", ap_escape_html(r->pool, r->method),
-                             "&nbsp;", 
-                             ap_escape_html(r->pool, r->uri), "</A></EM>.<P>\n"
+                             "&nbsp;",
+                          ap_escape_html(r->pool, r->uri), "</A></EM>.<P>\n"
                              "Reason: <STRONG>",
-                             ap_escape_html(r->pool, message), 
+                             ap_escape_html(r->pool, message),
                              "</STRONG>", NULL));
 
     /* Allow "error-notes" string to be printed by ap_send_error_response() */
@@ -938,7 +958,7 @@ int ap_proxyerror(request_rec *r, int statuscode, const char *message)
  * This routine returns its own error message
  */
 const char *
-     ap_proxy_host2addr(const char *host, struct hostent *reqhp)
+     ap_proxy_host2addr(const char *host, struct hostent * reqhp)
 {
     int i;
     struct hostent *hp;
@@ -955,14 +975,14 @@ const char *
     }
     else {
         ptd->ipaddr = ap_inet_addr(host);
-        hp = gethostbyaddr((char *) &ptd->ipaddr, sizeof(ptd->ipaddr), AF_INET);
+        hp = gethostbyaddr((char *)&ptd->ipaddr, sizeof(ptd->ipaddr), AF_INET);
         if (hp == NULL) {
             memset(&ptd->hpbuf, 0, sizeof(ptd->hpbuf));
             ptd->hpbuf.h_name = 0;
             ptd->hpbuf.h_addrtype = AF_INET;
             ptd->hpbuf.h_length = sizeof(ptd->ipaddr);
             ptd->hpbuf.h_addr_list = ptd->charpbuf;
-            ptd->hpbuf.h_addr_list[0] = (char *) &ptd->ipaddr;
+            ptd->hpbuf.h_addr_list[0] = (char *)&ptd->ipaddr;
             ptd->hpbuf.h_addr_list[1] = 0;
             hp = &ptd->hpbuf;
         }
@@ -985,13 +1005,14 @@ static const char *
         || url[1] != '/' || url[2] != '/')
         return NULL;
 
-    url = ap_pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
+    url = ap_pstrdup(r->pool, &url[1]); /* make it point to "//", which is
+                                         * what proxy_canon_netloc expects */
 
     err = ap_proxy_canon_netloc(r->pool, &url, &user, &password, &host, &port);
 
     if (err != NULL)
-        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r,
-                     "%s", err);
+        ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, r,
+                      "%s", err);
 
     r->hostname = host;
 
@@ -1011,9 +1032,12 @@ int ap_proxy_is_ipaddr(struct dirconn_entry *This, pool *p)
     /* "partial" addresses (with less than 4 quads) correctly, i.e.  */
     /* 192.168.123 is parsed as 192.168.0.123, which is not what I want. */
     /* I therefore have to parse the IP address manually: */
-    /*if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0) */
+    /*
+     * if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr)
+     * == 0)
+     */
     /* addr and mask were set by proxy_readmask() */
-    /*return 1; */
+    /* return 1; */
 
     /* Parse IP addr manually, optionally allowing */
     /* abbreviated net addresses like 192.168. */
@@ -1070,7 +1094,10 @@ int ap_proxy_is_ipaddr(struct dirconn_entry *This, pool *p)
         while (quads > 0 && ip_addr[quads - 1] == 0)
             --quads;
 
-        /* "IP Address should be given in dotted-quad form, optionally followed by a netmask (e.g., 192.168.111.0/24)"; */
+        /*
+         * "IP Address should be given in dotted-quad form, optionally
+         * followed by a netmask (e.g., 192.168.111.0/24)";
+         */
         if (quads < 1)
             return 0;
 
@@ -1111,8 +1138,8 @@ static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
     const char *found;
     const char *host = proxy_get_host_of_request(r);
 
-    if (host == NULL)   /* oops! */
-       return 0;
+    if (host == NULL)           /* oops! */
+        return 0;
 
     memset(&addr, '\0', sizeof addr);
     memset(ip_addr, '\0', sizeof ip_addr);
@@ -1157,7 +1184,7 @@ static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
 
         /* Try to deal with multiple IP addr's for a host */
         for (ip_listptr = the_host.h_addr_list; *ip_listptr; ++ip_listptr) {
-            ip_list = (struct in_addr *) *ip_listptr;
+            ip_list = (struct in_addr *)*ip_listptr;
             if (This->addr.s_addr == (ip_list->s_addr & This->mask.s_addr)) {
 #if DEBUGGING
                 fprintf(stderr, "3)IP-Match: %s[%s] <-> ", found, inet_ntoa(*ip_list));
@@ -1256,7 +1283,7 @@ int ap_proxy_is_hostname(struct dirconn_entry *This, pool *p)
     if (addr[i] != '\0' || ap_proxy_host2addr(addr, &host) != NULL)
         return 0;
 
-    This->hostentry = ap_pduphostent (p, &host);
+    This->hostentry = ap_pduphostent(p, &host);
 
     /* Strip trailing dots */
     for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i)
@@ -1275,7 +1302,7 @@ static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
     int h1_len;
 
     if (host == NULL || host2 == NULL)
-       return 0; /* oops! */
+        return 0;               /* oops! */
 
     h2_len = strlen(host2);
     h1_len = strlen(host);
@@ -1318,16 +1345,16 @@ int ap_proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r)
 
     ap_hard_timeout("proxy connect", r);
     do {
-        i = connect(sock, (struct sockaddr *) addr, sizeof(struct sockaddr_in));
+        i = connect(sock, (struct sockaddr *)addr, sizeof(struct sockaddr_in));
 #if defined(WIN32) || defined(NETWARE)
         if (i == SOCKET_ERROR)
             errno = WSAGetLastError();
-#endif /* WIN32 */
+#endif                          /* WIN32 */
     } while (i == -1 && errno == EINTR);
     if (i == -1) {
         ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                     "proxy connect to %s port %d failed",
-                     inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
+                      "proxy connect to %s port %d failed",
+                      inet_ntoa(addr->sin_addr), ntohs(addr->sin_port));
     }
     ap_kill_timeout(r);
 
@@ -1342,16 +1369,17 @@ int ap_proxy_send_hdr_line(void *p, const char *key, const char *value)
 {
     cache_req *c = (cache_req *)p;
 
-      if (key == NULL || value == NULL || value[0] == '\0')
+    if (key == NULL || value == NULL || value[0] == '\0')
         return 1;
-      if (c->fp != NULL &&
+    if (c->fp != NULL &&
         ap_bvputs(c->fp, key, ": ", value, CRLF, NULL) == -1) {
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
-                    "proxy: error writing header to %s", c->tempfile);
-          c = ap_proxy_cache_error(c);
-            return 0; /* no need to continue, it failed already */
+        ap_log_rerror(APLOG_MARK, APLOG_ERR, c->req,
+                      "proxy: error writing header to %s", c->tempfile);
+        c = ap_proxy_cache_error(c);
+        return 0;               /* no need to continue, it failed already */
     }
-    return 1; /* tell ap_table_do() to continue calling us for more headers */
+    return 1;                   /* tell ap_table_do() to continue calling us
+                                 * for more headers */
 }
 
 /* send a text line to one or two BUFF's; return line length */
@@ -1366,7 +1394,8 @@ unsigned ap_proxy_bputs2(const char *data, BUFF *client, cache_req *cache)
 /* do a HTTP/1.1 age calculation */
 time_t ap_proxy_current_age(cache_req *c, const time_t age_value)
 {
-    time_t apparent_age, corrected_received_age, response_delay, corrected_initial_age, resident_time, current_age;
+    time_t apparent_age, corrected_received_age, response_delay, corrected_initial_age,
+           resident_time, current_age;
 
     /* Perform an HTTP/1.1 age calculation. (RFC2616 13.2.3) */
 
@@ -1398,7 +1427,7 @@ BUFF *ap_proxy_open_cachefile(request_rec *r, char *filename)
                           "proxy: error opening cache file %s",
                           filename);
         else
-            ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, r->server, "File %s not found", filename);
+            ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, r->server, "File %s not found", filename);
 
     }
     return cachefp;
@@ -1432,10 +1461,10 @@ void ap_proxy_clear_connection(pool *p, table *headers)
     char *next = ap_pstrdup(p, ap_table_get(headers, "Connection"));
 
     ap_table_unset(headers, "Proxy-Connection");
-        if (!next) 
+    if (!next)
         return;
 
-    while (*next) { 
+    while (*next) {
         name = next;
         while (*next && !ap_isspace(*next) && (*next != ','))
             ++next;
@@ -1467,7 +1496,7 @@ void ap_proxy_clear_connection(pool *p, table *headers)
  */
 int ap_proxy_table_replace(table *base, table *overlay)
 {
-    table_entry *elts = (table_entry *) overlay->a.elts;
+    table_entry *elts = (table_entry *)overlay->a.elts;
     int i, q = 0;
     const char *val;
 
@@ -1523,21 +1552,21 @@ void ap_proxy_table_unmerge(pool *p, table *t, char *key)
 
 static DWORD tls_index;
 
-BOOL WINAPI DllMain (HINSTANCE dllhandle, DWORD reason, LPVOID reserved)
+BOOL WINAPI DllMain(HINSTANCE dllhandle, DWORD reason, LPVOID reserved)
 {
     LPVOID memptr;
 
     switch (reason) {
     case DLL_PROCESS_ATTACH:
         tls_index = TlsAlloc();
-    case DLL_THREAD_ATTACH: /* intentional no break */
-        TlsSetValue (tls_index, malloc (sizeof (struct per_thread_data)));
+    case DLL_THREAD_ATTACH:     /* intentional no break */
+        TlsSetValue(tls_index, malloc(sizeof(struct per_thread_data)));
         break;
     case DLL_THREAD_DETACH:
-        memptr = TlsGetValue (tls_index);
+        memptr = TlsGetValue(tls_index);
         if (memptr) {
-            free (memptr);
-            TlsSetValue (tls_index, 0);
+            free(memptr);
+            TlsSetValue(tls_index, 0);
         }
         break;
     }
@@ -1551,7 +1580,7 @@ static struct per_thread_data *get_per_thread_data(void)
 {
 #if defined(WIN32)
 
-    return (struct per_thread_data *) TlsGetValue (tls_index);
+    return (struct per_thread_data *)TlsGetValue(tls_index);
 
 #else