httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@hyperreal.org>
Subject cvs commit: apachen/src/modules/proxy .indent.pro mod_proxy.c mod_proxy.h proxy_cache.c proxy_connect.c proxy_ftp.c proxy_http.c proxy_util.c
Date Tue, 16 Sep 1997 00:59:51 GMT
dgaudet     97/09/15 17:59:48

  Modified:    src/modules/proxy mod_proxy.c mod_proxy.h proxy_cache.c
                        proxy_connect.c proxy_ftp.c proxy_http.c
                        proxy_util.c
  Added:       src/modules/proxy .indent.pro
  Log:
  painful indent
  
  Revision  Changes    Path
  1.25      +274 -271  apachen/src/modules/proxy/mod_proxy.c
  
  Index: mod_proxy.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/mod_proxy.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- mod_proxy.c	1997/09/05 00:26:32	1.24
  +++ mod_proxy.c	1997/09/16 00:59:38	1.25
  @@ -55,16 +55,17 @@
   
   /* Some WWW schemes and their default ports; this is basically /etc/services */
   /* This will become global when the protocol abstraction comes */
  -static struct proxy_services defports[]={
  -    { "ftp",      DEFAULT_FTP_PORT},
  -    { "gopher",   DEFAULT_GOPHER_PORT},
  -    { "http",     DEFAULT_PORT},
  -    { "nntp",     DEFAULT_NNTP_PORT},
  -    { "wais",     DEFAULT_WAIS_PORT}, 
  -    { "https",    DEFAULT_HTTPS_PORT},
  -    { "snews",    DEFAULT_SNEWS_PORT},
  -    { "prospero", DEFAULT_PROSPERO_PORT},
  -    { NULL, -1}  /* unknown port */
  +static struct proxy_services defports[] =
  +{
  +    {"ftp", DEFAULT_FTP_PORT},
  +    {"gopher", DEFAULT_GOPHER_PORT},
  +    {"http", DEFAULT_PORT},
  +    {"nntp", DEFAULT_NNTP_PORT},
  +    {"wais", DEFAULT_WAIS_PORT},
  +    {"https", DEFAULT_HTTPS_PORT},
  +    {"snews", DEFAULT_SNEWS_PORT},
  +    {"prospero", DEFAULT_PROSPERO_PORT},
  +    {NULL, -1}			/* unknown port */
   };
   
   /*
  @@ -80,27 +81,28 @@
   /* -------------------------------------------------------------- */
   /* Translate the URL into a 'filename' */
   
  -static int
  -alias_match(char *uri, char *alias_fakename)
  +static int alias_match(char *uri, char *alias_fakename)
   {
  -    char *end_fakename = alias_fakename + strlen (alias_fakename);
  +    char *end_fakename = alias_fakename + strlen(alias_fakename);
       char *aliasp = alias_fakename, *urip = uri;
   
  -    while (aliasp < end_fakename)
  -    {
  -	if (*aliasp == '/')
  -	{
  +    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...
   	     */
  -	    if (*urip != '/') return 0;
  -	    
  -	    while (*aliasp == '/') ++ aliasp;
  -	    while (*urip == '/') ++ urip;
  +	    if (*urip != '/')
  +		return 0;
  +
  +	    while (*aliasp == '/')
  +		++aliasp;
  +	    while (*urip == '/')
  +		++urip;
   	}
   	else {
   	    /* Other characters are compared literally */
  -	    if (*urip++ != *aliasp++) return 0;
  +	    if (*urip++ != *aliasp++)
  +		return 0;
   	}
       }
   
  @@ -117,31 +119,28 @@
       return urip - uri;
   }
   
  -static int
  -proxy_trans(request_rec *r)
  +static int proxy_trans(request_rec *r)
   {
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  +    (proxy_server_conf *) get_module_config(sconf, &proxy_module);
  +
  +    if (r->proxyreq) {
  +	if (!conf->req)
  +	    return DECLINED;
   
  -    if (r->proxyreq)
  -    {
  -	if (!conf->req) return DECLINED;
  -	
   	r->filename = pstrcat(r->pool, "proxy:", r->uri, NULL);
   	r->handler = "proxy-server";
   	return OK;
  -    } else
  -    {
  +    }
  +    else {
   	int i, len;
  -	struct proxy_alias *ent=(struct proxy_alias *)conf->aliases->elts;
  +	struct proxy_alias *ent = (struct proxy_alias *) conf->aliases->elts;
   
  -	for (i=0; i < conf->aliases->nelts; i++)
  -	{
  +	for (i = 0; i < conf->aliases->nelts; i++) {
   	    len = alias_match(r->uri, ent[i].fake);
   
  -	    if (len > 0)
  -	    {
  +	    if (len > 0) {
   		r->filename = pstrcat(r->pool, "proxy:", ent[i].real,
   				      r->uri + len, NULL);
   		r->handler = "proxy-server";
  @@ -158,33 +157,35 @@
   /*
    * Canonicalise the URL
    */
  -static int
  -proxy_fixup(request_rec *r)
  +static int proxy_fixup(request_rec *r)
   {
       char *url, *p;
       int i;
   
  -    if (strncmp(r->filename, "proxy:", 6) != 0) return DECLINED;
  +    if (strncmp(r->filename, "proxy:", 6) != 0)
  +	return DECLINED;
   
       url = &r->filename[6];
   /* lowercase the scheme */
       p = strchr(url, ':');
  -    if (p == NULL || p == url) return BAD_REQUEST;
  -    for (i=0; i != p - url; i++) url[i] = tolower(url[i]);
  +    if (p == NULL || p == url)
  +	return BAD_REQUEST;
  +    for (i = 0; i != p - url; i++)
  +	url[i] = tolower(url[i]);
   
   /* canonicalise each specific scheme */
       if (strncmp(url, "http:", 5) == 0)
  -	return proxy_http_canon(r, url+5, "http", DEFAULT_PORT);
  +	return proxy_http_canon(r, url + 5, "http", DEFAULT_PORT);
       else if (strncmp(url, "ftp:", 4) == 0)
  -	return proxy_ftp_canon(r, url+4);
  -    else return OK; /* otherwise; we've done the best we can */
  +	return proxy_ftp_canon(r, url + 4);
  +    else
  +	return OK;		/* otherwise; we've done the best we can */
   }
   
  -static void
  -proxy_init(server_rec *r, pool *p)
  +static void proxy_init(server_rec *r, pool *p)
   {
       proxy_garbage_init(r, p);
  -} 
  +}
   
   
   
  @@ -194,27 +195,27 @@
   /* domain in this case. I think it is better to redirect to a FQDN, since */
   /* these will later be found in the bookmarks files. */
   /* The "ProxyDomain" directive determines what domain will be appended */
  -static int
  -proxy_needsdomain(request_rec *r, const char *url, const char *domain)
  +static int proxy_needsdomain(request_rec *r, const char *url, const char *domain)
   {
  -    char *scheme = pstrdup (r->pool, url);
  +    char *scheme = pstrdup(r->pool, url);
       char *url_copy, *user = NULL, *password = NULL, *path, *err, *host;
       int port = -1;
   
       /* We only want to worry about GETs */
  -    if (r->method_number != M_GET) return DECLINED;
  +    if (r->method_number != M_GET)
  +	return DECLINED;
   
       /* Set url to the first char after "scheme://" */
  -    if ((url_copy = strchr(scheme,':')) == NULL
  +    if ((url_copy = strchr(scheme, ':')) == NULL
   	|| url_copy[1] != '/' || url_copy[2] != '/')
   	return DECLINED;
   
  -    *url_copy++ = '\0';	/* delimit scheme, make url_copy point to "//", which is what proxy_canon_netloc expects */
  +    *url_copy++ = '\0';		/* delimit scheme, make url_copy point to "//", which is what proxy_canon_netloc expects */
   
       /* Save the path - it will be re-appended for the redirection later */
       path = strchr(&url_copy[2], '/');
       if (path != NULL)
  -	++path;	    /* leading '/' will be overwritten by proxy_canon_netloc */
  +	++path;			/* leading '/' will be overwritten by proxy_canon_netloc */
       else
   	path = "";
   
  @@ -227,32 +228,31 @@
       }
   
       /* If host does contain a dot already, or it is "localhost", decline */
  -    if (strchr (host, '.') != NULL || strcasecmp(host, "localhost") == 0)
  +    if (strchr(host, '.') != NULL || strcasecmp(host, "localhost") == 0)
   	return DECLINED;	/* host name has a dot already */
  -    else
  -    {
  +    else {
   	char *nuri;
   	char *ref = table_get(r->headers_in, "Referer");
   	char strport[10];
   
   	/* now, rebuild URL */
   	if (port == -1)
  -	    strcpy (strport, "");
  +	    strcpy(strport, "");
   	else
   	    ap_snprintf(strport, sizeof(strport), ":%d", port);
   
   	/* Reassemble the request, but insert the domain after the host name */
   	nuri = pstrcat(r->pool, scheme, "://", (user != NULL) ? user : "",
  -		       (password != NULL) ? ":" : "",
  -		       (password != NULL) ? password : "",
  -		       (user != NULL) ? "@" : "",
  +		            (password != NULL) ? ":" : "",
  +		            (password != NULL) ? password : "",
  +		            (user != NULL) ? "@" : "",
   		       host, domain, strport, "/", path,
   		       NULL);
   
   	table_set(r->headers_out, "Location", nuri);
   	aplog_error(APLOG_MARK, APLOG_ERR, r->server,
  -		    pstrcat(r->pool, "Domain missing: ", r->uri, " sent to ", nuri,
  -			    ref ? " from " : NULL, ref, NULL));
  +	     pstrcat(r->pool, "Domain missing: ", r->uri, " sent to ", nuri,
  +		     ref ? " from " : NULL, ref, NULL));
   
   	return REDIRECT;
       }
  @@ -260,31 +260,33 @@
   
   /* -------------------------------------------------------------- */
   /* Invoke handler */
  - 
  -static int
  -proxy_handler(request_rec *r)
  +
  +static int proxy_handler(request_rec *r)
   {
       char *url, *scheme, *p;
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  -    array_header *proxies=conf->proxies;
  -    struct proxy_remote *ents=(struct proxy_remote *)proxies->elts;
  +    (proxy_server_conf *) get_module_config(sconf, &proxy_module);
  +    array_header *proxies = conf->proxies;
  +    struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
       int i, rc;
       struct cache_req *cr;
       int direct_connect = 0;
   
  -    if (strncmp(r->filename, "proxy:", 6) != 0) return DECLINED;
  +    if (strncmp(r->filename, "proxy:", 6) != 0)
  +	return DECLINED;
   
       if ((rc = setup_client_block(r, REQUEST_CHUNKED_ERROR)))
   	return rc;
   
       url = r->filename + 6;
       p = strchr(url, ':');
  -    if (p == NULL) return BAD_REQUEST;
  +    if (p == NULL)
  +	return BAD_REQUEST;
   
       rc = proxy_cache_check(r, url, &conf->cache, &cr);
  -    if (rc != DECLINED) return rc;
  +    if (rc != DECLINED)
  +	return rc;
   
       /* If the host doesn't have a domain name, add one and redirect. */
       if (conf->domain != NULL
  @@ -298,56 +300,55 @@
       /* 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 (strcmp(scheme, "http") == 0)*/
  +    /*if (strcmp(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;
   
   /*        if (*++p == '/' && *++p == '/')   */
   
  -	for (direct_connect=ii=0; ii < conf->dirconn->nelts && !direct_connect; ii++)
  -	{
  -	    direct_connect = list[ii].matcher (&list[ii], r);
  +	for (direct_connect = ii = 0; ii < conf->dirconn->nelts && !direct_connect; ii++) {
  +	    direct_connect = list[ii].matcher(&list[ii], r);
   	    aplog_error(APLOG_MARK, APLOG_DEBUG, r->server,
   			"URI and NoProxy: %s: %s", r->uri, list[ii].name);
   	}
   #if DEBUGGING
   	{
   	    char msg[256];
  -	    sprintf (msg, (direct_connect)?"NoProxy for %s":"UseProxy for %s", r->uri);
  +	    sprintf(msg, (direct_connect) ? "NoProxy for %s" : "UseProxy for %s", r->uri);
   	    aplog_error(APLOG_MARK, APLOG_DEBUG, r->server, msg);
   	}
   #endif
       }
  -	
  +
   /* firstly, try a proxy, unless a NoProxy directive is active */
   
       if (!direct_connect)
  -    for (i=0; i < proxies->nelts; i++)
  -    {
  -	p = strchr(ents[i].scheme, ':');  /* is it a partial URL? */
  -	if (strcmp(ents[i].scheme, "*") == 0 || 
  -	    (p == NULL && strcmp(scheme, ents[i].scheme) == 0) ||
  -	    (p != NULL &&
  -	       strncmp(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 = proxy_connect_handler(r, cr, url, ents[i].hostname,
  -		    ents[i].port);
  +	for (i = 0; i < proxies->nelts; i++) {
  +	    p = strchr(ents[i].scheme, ':');	/* is it a partial URL? */
  +	    if (strcmp(ents[i].scheme, "*") == 0 ||
  +		(p == NULL && strcmp(scheme, ents[i].scheme) == 0) ||
  +		(p != NULL &&
  +	       strncmp(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 = proxy_connect_handler(r, cr, url, ents[i].hostname,
  +					       ents[i].port);
   /* we only know how to handle communication to a proxy via http */
  -	    else if (strcmp(ents[i].protocol, "http") == 0)
  -		rc = proxy_http_handler(r, cr, url, ents[i].hostname,
  -		    ents[i].port);
  -	    else rc = DECLINED;
  -
  - /* an error or success */
  -	    if (rc != DECLINED && rc != BAD_GATEWAY) return rc;
  - /* we failed to talk to the upstream proxy */
  +		else if (strcmp(ents[i].protocol, "http") == 0)
  +		    rc = proxy_http_handler(r, cr, url, ents[i].hostname,
  +					    ents[i].port);
  +		else
  +		    rc = DECLINED;
  +
  +		/* an error or success */
  +		if (rc != DECLINED && rc != BAD_GATEWAY)
  +		    return rc;
  +		/* we failed to talk to the upstream proxy */
  +	    }
   	}
  -    }
   
   /* otherwise, try it direct */
   /* N.B. what if we're behind a firewall, where we must use a proxy or
  @@ -360,44 +361,45 @@
   	return proxy_http_handler(r, cr, url, NULL, 0);
       if (strcmp(scheme, "ftp") == 0)
   	return proxy_ftp_handler(r, cr, url);
  -    else return NOT_IMPLEMENTED;
  +    else
  +	return NOT_IMPLEMENTED;
   }
   
   /* -------------------------------------------------------------- */
   /* Setup configurable data */
   
   static void *
  -create_proxy_config(pool *p, server_rec *s)
  +     create_proxy_config(pool *p, server_rec *s)
   {
  -  proxy_server_conf *ps = pcalloc(p, sizeof(proxy_server_conf));
  +    proxy_server_conf *ps = pcalloc(p, sizeof(proxy_server_conf));
   
  -  ps->proxies = make_array(p, 10, sizeof(struct proxy_remote));
  -  ps->aliases = make_array(p, 10, sizeof(struct proxy_alias));
  -  ps->noproxies = make_array(p, 10, sizeof(struct noproxy_entry));
  -  ps->dirconn = make_array(p, 10, sizeof(struct dirconn_entry));
  -  ps->nocaches = make_array(p, 10, sizeof(struct nocache_entry));
  -  ps->domain = NULL;
  -  ps->req = 0;
  +    ps->proxies = make_array(p, 10, sizeof(struct proxy_remote));
  +    ps->aliases = make_array(p, 10, sizeof(struct proxy_alias));
  +    ps->noproxies = make_array(p, 10, sizeof(struct noproxy_entry));
  +    ps->dirconn = make_array(p, 10, sizeof(struct dirconn_entry));
  +    ps->nocaches = make_array(p, 10, sizeof(struct nocache_entry));
  +    ps->domain = NULL;
  +    ps->req = 0;
   
  -  ps->cache.root = NULL;
  -  ps->cache.space = DEFAULT_CACHE_SPACE;
  -  ps->cache.maxexpire = DEFAULT_CACHE_MAXEXPIRE;
  -  ps->cache.defaultexpire = DEFAULT_CACHE_EXPIRE;
  -  ps->cache.lmfactor = DEFAULT_CACHE_LMFACTOR;
  -  ps->cache.gcinterval = -1;
  -  /* at these levels, the cache can have 2^18 directories (256,000)  */
  -  ps->cache.dirlevels=3;
  -  ps->cache.dirlength=1;
  +    ps->cache.root = NULL;
  +    ps->cache.space = DEFAULT_CACHE_SPACE;
  +    ps->cache.maxexpire = DEFAULT_CACHE_MAXEXPIRE;
  +    ps->cache.defaultexpire = DEFAULT_CACHE_EXPIRE;
  +    ps->cache.lmfactor = DEFAULT_CACHE_LMFACTOR;
  +    ps->cache.gcinterval = -1;
  +    /* at these levels, the cache can have 2^18 directories (256,000)  */
  +    ps->cache.dirlevels = 3;
  +    ps->cache.dirlength = 1;
   
  -  return ps;
  +    return ps;
   }
   
   static const char *
  -add_proxy(cmd_parms *cmd, void *dummy, char *f, char *r)
  +     add_proxy(cmd_parms *cmd, void *dummy, char *f, char *r)
   {
       server_rec *s = cmd->server;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(s->module_config,&proxy_module);
  +    (proxy_server_conf *) get_module_config(s->module_config, &proxy_module);
       struct proxy_remote *new;
       char *p, *q;
       int port;
  @@ -406,25 +408,27 @@
       if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
   	return "Bad syntax for a remote proxy server";
       q = strchr(p + 3, ':');
  -    if (q != NULL)
  -    {
  -	if (sscanf(q+1, "%u", &port) != 1 || port > 65535)
  +    if (q != NULL) {
  +	if (sscanf(q + 1, "%u", &port) != 1 || port > 65535)
   	    return "Bad syntax for a remote proxy server (bad port number)";
   	*q = '\0';
  -    } else port = -1;
  +    }
  +    else
  +	port = -1;
       *p = '\0';
  -    if (strchr(f, ':') == NULL) str_tolower(f);     /* lowercase scheme */
  -    str_tolower(p + 3); /* lowercase hostname */
  +    if (strchr(f, ':') == NULL)
  +	str_tolower(f);		/* lowercase scheme */
  +    str_tolower(p + 3);		/* lowercase hostname */
   
  -    if (port == -1)
  -    {
  +    if (port == -1) {
   	int i;
  -	for (i=0; defports[i].scheme != NULL; i++)
  -	    if (strcmp(defports[i].scheme, r) == 0) break;
  +	for (i = 0; defports[i].scheme != NULL; i++)
  +	    if (strcmp(defports[i].scheme, r) == 0)
  +		break;
   	port = defports[i].port;
       }
   
  -    new = push_array (conf->proxies);
  +    new = push_array(conf->proxies);
       new->scheme = f;
       new->protocol = r;
       new->hostname = p + 3;
  @@ -433,41 +437,39 @@
   }
   
   static const char *
  -add_pass(cmd_parms *cmd, void *dummy, char *f, char *r)
  +     add_pass(cmd_parms *cmd, void *dummy, char *f, char *r)
   {
       server_rec *s = cmd->server;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(s->module_config,&proxy_module);
  +    (proxy_server_conf *) get_module_config(s->module_config, &proxy_module);
       struct proxy_alias *new;
   
  -    new = push_array (conf->aliases);
  +    new = push_array(conf->aliases);
       new->fake = f;
       new->real = r;
       return NULL;
   }
   
   static const char *
  -set_proxy_exclude(cmd_parms *parms, void *dummy, char *arg)
  +     set_proxy_exclude(cmd_parms *parms, void *dummy, char *arg)
   {
       server_rec *s = parms->server;
       proxy_server_conf *conf =
  -	get_module_config (s->module_config, &proxy_module);
  +    get_module_config(s->module_config, &proxy_module);
       struct noproxy_entry *new;
  -    struct noproxy_entry *list=(struct noproxy_entry*)conf->noproxies->elts;
  +    struct noproxy_entry *list = (struct noproxy_entry *) conf->noproxies->elts;
       struct hostent hp;
       int found = 0;
       int i;
   
       /* Don't duplicate entries */
  -    for (i=0; i < conf->noproxies->nelts; i++)
  -    {
  +    for (i = 0; i < conf->noproxies->nelts; i++) {
   	if (strcmp(arg, list[i].name) == 0)
   	    found = 1;
       }
   
  -    if (!found)
  -    {
  -	new = push_array (conf->noproxies);
  +    if (!found) {
  +	new = push_array(conf->noproxies);
   	new->name = arg;
   	/* Don't do name lookups on things that aren't dotted */
   	if (strchr(arg, '.') != NULL && proxy_host2addr(new->name, &hp) == NULL)
  @@ -482,54 +484,48 @@
    * which should never be accessed via the configured ProxyRemote servers
    */
   static const char *
  -set_proxy_dirconn(cmd_parms *parms, void *dummy, char *arg)
  +     set_proxy_dirconn(cmd_parms *parms, void *dummy, char *arg)
   {
       server_rec *s = parms->server;
       proxy_server_conf *conf =
  -	get_module_config (s->module_config, &proxy_module);
  +    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;
   
       /* Don't duplicate entries */
  -    for (i=0; i < conf->dirconn->nelts; i++)
  -    {
  +    for (i = 0; i < conf->dirconn->nelts; i++) {
   	if (strcasecmp(arg, list[i].name) == 0)
   	    found = 1;
       }
   
  -    if (!found)
  -    {
  -	New = push_array (conf->dirconn);
  +    if (!found) {
  +	New = push_array(conf->dirconn);
   	New->name = arg;
   
  -	if (proxy_is_ipaddr(New))
  -	{
  +	if (proxy_is_ipaddr(New)) {
   #if DEBUGGING
  -	    fprintf(stderr,"Parsed addr %s\n", inet_ntoa(New->addr));
  -	    fprintf(stderr,"Parsed mask %s\n", inet_ntoa(New->mask));
  +	    fprintf(stderr, "Parsed addr %s\n", inet_ntoa(New->addr));
  +	    fprintf(stderr, "Parsed mask %s\n", inet_ntoa(New->mask));
   #endif
   	}
  -	else if (proxy_is_domainname(New))
  -	{
  +	else if (proxy_is_domainname(New)) {
   	    str_tolower(New->name);
   #if DEBUGGING
  -	    fprintf(stderr,"Parsed domain %s\n", New->name);
  +	    fprintf(stderr, "Parsed domain %s\n", New->name);
   #endif
   	}
  -	else if (proxy_is_hostname(New))
  -	{
  +	else if (proxy_is_hostname(New)) {
   	    str_tolower(New->name);
   #if DEBUGGING
  -	    fprintf(stderr,"Parsed host %s\n", New->name);
  +	    fprintf(stderr, "Parsed host %s\n", New->name);
   #endif
   	}
  -	else
  -	{
  +	else {
   	    proxy_is_word(New);
   #if DEBUGGING
  -	    fprintf(stderr,"Parsed word %s\n", New->name);
  +	    fprintf(stderr, "Parsed word %s\n", New->name);
   #endif
   	}
       }
  @@ -537,10 +533,10 @@
   }
   
   static const char *
  -set_proxy_domain(cmd_parms *parms, void *dummy, char *arg)
  +     set_proxy_domain(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
   
       if (arg[0] != '.')
   	return "Domain name must start with a dot.";
  @@ -550,10 +546,10 @@
   }
   
   static const char *
  -set_proxy_req(cmd_parms *parms, void *dummy, int flag)
  +     set_proxy_req(cmd_parms *parms, void *dummy, int flag)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
   
       psf->req = flag;
       return NULL;
  @@ -561,22 +557,23 @@
   
   
   static const char *
  -set_cache_size(cmd_parms *parms, char *struct_ptr, char *arg)
  +     set_cache_size(cmd_parms *parms, char *struct_ptr, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       int val;
   
  -    if (sscanf(arg, "%d", &val) != 1) return "Value must be an integer";
  +    if (sscanf(arg, "%d", &val) != 1)
  +	return "Value must be an integer";
       psf->cache.space = val;
       return NULL;
   }
   
   static const char *
  -set_cache_root(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_root(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
   
       psf->cache.root = arg;
   
  @@ -584,184 +581,190 @@
   }
   
   static const char *
  -set_cache_factor(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_factor(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       double val;
   
  -    if (sscanf(arg, "%lg", &val) != 1) return "Value must be a float";
  +    if (sscanf(arg, "%lg", &val) != 1)
  +	return "Value must be a float";
       psf->cache.lmfactor = val;
   
       return NULL;
   }
   
   static const char *
  -set_cache_maxex(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_maxex(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       double val;
   
  -    if (sscanf(arg, "%lg", &val) != 1) return "Value must be a float";
  -    psf->cache.maxexpire = (int)(val * (double)SEC_ONE_HR);
  +    if (sscanf(arg, "%lg", &val) != 1)
  +	return "Value must be a float";
  +    psf->cache.maxexpire = (int) (val * (double) SEC_ONE_HR);
       return NULL;
   }
   
   static const char *
  -set_cache_defex(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_defex(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       double val;
   
  -    if (sscanf(arg, "%lg", &val) != 1) return "Value must be a float";
  -    psf->cache.defaultexpire = (int)(val * (double)SEC_ONE_HR);
  +    if (sscanf(arg, "%lg", &val) != 1)
  +	return "Value must be a float";
  +    psf->cache.defaultexpire = (int) (val * (double) SEC_ONE_HR);
       return NULL;
   }
   
   static const char *
  -set_cache_gcint(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_gcint(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       double val;
   
  -    if (sscanf(arg, "%lg", &val) != 1) return "Value must be a float";
  -    psf->cache.gcinterval = (int)(val * (double)SEC_ONE_HR);
  +    if (sscanf(arg, "%lg", &val) != 1)
  +	return "Value must be a float";
  +    psf->cache.gcinterval = (int) (val * (double) SEC_ONE_HR);
       return NULL;
   }
   
   static const char *
  -set_cache_dirlevels(cmd_parms *parms, char *struct_ptr, char *arg)
  +     set_cache_dirlevels(cmd_parms *parms, char *struct_ptr, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       int val;
   
  -    if (sscanf(arg, "%d", &val) != 1) return "Value must be an integer";
  +    if (sscanf(arg, "%d", &val) != 1)
  +	return "Value must be an integer";
       psf->cache.dirlevels = val;
       return NULL;
   }
   
   static const char *
  -set_cache_dirlength(cmd_parms *parms, char *struct_ptr, char *arg)
  +     set_cache_dirlength(cmd_parms *parms, char *struct_ptr, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  +    get_module_config(parms->server->module_config, &proxy_module);
       int val;
   
  -    if (sscanf(arg, "%d", &val) != 1) return "Value must be an integer";
  +    if (sscanf(arg, "%d", &val) != 1)
  +	return "Value must be an integer";
       psf->cache.dirlength = val;
       return NULL;
   }
   
   static const char *
  -set_cache_exclude(cmd_parms *parms, void *dummy, char *arg)
  +     set_cache_exclude(cmd_parms *parms, void *dummy, char *arg)
   {
       server_rec *s = parms->server;
       proxy_server_conf *conf =
  -	get_module_config (s->module_config, &proxy_module);
  +    get_module_config(s->module_config, &proxy_module);
       struct nocache_entry *new;
  -    struct nocache_entry *list=(struct nocache_entry*)conf->nocaches->elts;
  +    struct nocache_entry *list = (struct nocache_entry *) conf->nocaches->elts;
       struct hostent hp;
       int found = 0;
       int i;
   
       /* Don't duplicate entries */
  -    for (i=0; i < conf->nocaches->nelts; i++)
  -    {
  +    for (i = 0; i < conf->nocaches->nelts; i++) {
   	if (strcmp(arg, list[i].name) == 0)
   	    found = 1;
       }
   
  -    if (!found)
  -    {
  -	new = push_array (conf->nocaches);
  +    if (!found) {
  +	new = push_array(conf->nocaches);
   	new->name = arg;
   	/* Don't do name lookups on things that aren't dotted */
   	if (strchr(arg, '.') != NULL && proxy_host2addr(new->name, &hp) == NULL)
   	    memcpy(&new->addr, hp.h_addr, sizeof(struct in_addr));
   	else
  -	    new->addr.s_addr= 0;
  +	    new->addr.s_addr = 0;
       }
       return NULL;
   }
   
   static const char *
  -set_recv_buffer_size (cmd_parms *parms, void *dummy, char *arg)
  +     set_recv_buffer_size(cmd_parms *parms, void *dummy, char *arg)
   {
       proxy_server_conf *psf =
  -	get_module_config (parms->server->module_config, &proxy_module);
  -    int s = atoi (arg);
  -    if (s < 512 && s != 0)
  -    {
  -        return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
  +    get_module_config(parms->server->module_config, &proxy_module);
  +    int s = atoi(arg);
  +    if (s < 512 && s != 0) {
  +	return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
       }
   
       psf->recv_buffer_size = s;
       return NULL;
   }
   
  -static handler_rec proxy_handlers[] = {
  -{ "proxy-server", proxy_handler },
  -{ NULL } 
  -};  
  -    
  -static command_rec proxy_cmds[] = {
  -{ "ProxyRequests", set_proxy_req, NULL, RSRC_CONF, FLAG,
  -  "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"},
  -{ "ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,
  -    "a virtual path and a URL"},
  -{ "ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE,
  -    "A list of names, hosts or domains to which the proxy will not connect" },
  -{ "NoProxy", set_proxy_dirconn, NULL, RSRC_CONF, ITERATE,
  -    "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)" },
  -{ "CacheRoot", set_cache_root, NULL, RSRC_CONF, TAKE1,
  -      "The directory to store cache files"},
  -{ "CacheSize", set_cache_size, NULL, RSRC_CONF, TAKE1,
  -      "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"},
  -{ "CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF, TAKE1,
  -      "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"},
  -{ "CacheGcInterval", set_cache_gcint, NULL, RSRC_CONF, TAKE1,
  -      "The interval between garbage collections, in hours"},
  -{ "CacheDirLevels", set_cache_dirlevels, NULL, RSRC_CONF, TAKE1,
  -    "The number of levels of subdirectories in the cache" },
  -{ "CacheDirLength", set_cache_dirlength, NULL, RSRC_CONF, TAKE1,
  -    "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" },
  -{ "ReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1,
  -    "Receive buffer size in bytes" },
  -{ NULL }
  +static handler_rec proxy_handlers[] =
  +{
  +    {"proxy-server", proxy_handler},
  +    {NULL}
  +};
  +
  +static command_rec proxy_cmds[] =
  +{
  +    {"ProxyRequests", set_proxy_req, NULL, RSRC_CONF, FLAG,
  +     "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"},
  +    {"ProxyPass", add_pass, NULL, RSRC_CONF, TAKE2,
  +     "a virtual path and a URL"},
  +    {"ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF, ITERATE,
  +   "A list of names, hosts or domains to which the proxy will not connect"},
  +    {"NoProxy", set_proxy_dirconn, NULL, RSRC_CONF, ITERATE,
  +     "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)"},
  +    {"CacheRoot", set_cache_root, NULL, RSRC_CONF, TAKE1,
  +     "The directory to store cache files"},
  +    {"CacheSize", set_cache_size, NULL, RSRC_CONF, TAKE1,
  +     "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"},
  +    {"CacheDefaultExpire", set_cache_defex, NULL, RSRC_CONF, TAKE1,
  +     "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"},
  +    {"CacheGcInterval", set_cache_gcint, NULL, RSRC_CONF, TAKE1,
  +     "The interval between garbage collections, in hours"},
  +    {"CacheDirLevels", set_cache_dirlevels, NULL, RSRC_CONF, TAKE1,
  +     "The number of levels of subdirectories in the cache"},
  +    {"CacheDirLength", set_cache_dirlength, NULL, RSRC_CONF, TAKE1,
  +     "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"},
  +    {"ReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF, TAKE1,
  +     "Receive buffer size in bytes"},
  +    {NULL}
   };
   
  -module MODULE_VAR_EXPORT proxy_module = {
  -   STANDARD_MODULE_STUFF,
  -   proxy_init,                  /* initializer */
  -   NULL,                        /* create per-directory config structure */
  -   NULL,                        /* merge per-directory config structures */
  -   create_proxy_config,         /* create per-server config structure */
  -   NULL,                        /* merge per-server config structures */
  -   proxy_cmds,                  /* command table */
  -   proxy_handlers,              /* handlers */
  -   proxy_trans,                 /* translate_handler */
  -   NULL,                        /* check_user_id */
  -   NULL,                        /* check auth */
  -   NULL,                        /* check access */
  -   NULL,                        /* type_checker */
  -   proxy_fixup,                 /* pre-run fixups */
  -   NULL,                        /* logger */
  -   NULL,                        /* header parser */
  -   NULL,			/* child_init */
  -   NULL,			/* child_exit */
  -   NULL				/* post read-request */
  +module MODULE_VAR_EXPORT proxy_module =
  +{
  +    STANDARD_MODULE_STUFF,
  +    proxy_init,			/* initializer */
  +    NULL,			/* create per-directory config structure */
  +    NULL,			/* merge per-directory config structures */
  +    create_proxy_config,	/* create per-server config structure */
  +    NULL,			/* merge per-server config structures */
  +    proxy_cmds,			/* command table */
  +    proxy_handlers,		/* handlers */
  +    proxy_trans,		/* translate_handler */
  +    NULL,			/* check_user_id */
  +    NULL,			/* check auth */
  +    NULL,			/* check access */
  +    NULL,			/* type_checker */
  +    proxy_fixup,		/* pre-run fixups */
  +    NULL,			/* logger */
  +    NULL,			/* header parser */
  +    NULL,			/* child_init */
  +    NULL,			/* child_exit */
  +    NULL			/* post read-request */
   };
  
  
  
  1.23      +83 -88    apachen/src/modules/proxy/mod_proxy.h
  
  Index: mod_proxy.h
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/mod_proxy.h,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- mod_proxy.h	1997/09/06 14:16:56	1.22
  +++ mod_proxy.h	1997/09/16 00:59:39	1.23
  @@ -56,43 +56,43 @@
   
   /*
   
  -Note that the Explain() stuff is not yet complete.
  -Also note numerous FIXMEs and CHECKMEs which should be eliminated.
  +   Note that the Explain() stuff is not yet complete.
  +   Also note numerous FIXMEs and CHECKMEs which should be eliminated.
   
  -If TESTING is set, then garbage collection doesn't delete ... probably a good
  -idea when hacking.
  +   If TESTING is set, then garbage collection doesn't delete ... probably a good
  +   idea when hacking.
   
  -This code is still experimental!
  +   This code is still experimental!
   
  -Things to do:
  +   Things to do:
   
  -1. Make it garbage collect in the background, not while someone is waiting for
  -a response!
  +   1. Make it garbage collect in the background, not while someone is waiting for
  +   a response!
   
  -2. Check the logic thoroughly.
  +   2. Check the logic thoroughly.
   
  -3. Empty directories are only removed the next time round (but this does avoid
  -two passes). Consider doing them the first time round.
  +   3. Empty directories are only removed the next time round (but this does avoid
  +   two passes). Consider doing them the first time round.
   
  -Ben Laurie <ben@algroup.co.uk> 30 Mar 96
  +   Ben Laurie <ben@algroup.co.uk> 30 Mar 96
   
  -More things to do:
  +   More things to do:
   
  -0. Code cleanup (ongoing)
  +   0. Code cleanup (ongoing)
   
  -1. add 230 response output for ftp now that it works
  +   1. add 230 response output for ftp now that it works
   
  -2. Make the ftp proxy transparent, also same with (future) gopher & wais
  +   2. Make the ftp proxy transparent, also same with (future) gopher & wais
   
  -3. Use protocol handler struct a la Apache module handlers (Dirk van Gulik)
  - 
  -4. Use a cache expiry database for more efficient GC (Jeremy Wohl)
  +   3. Use protocol handler struct a la Apache module handlers (Dirk van Gulik)
   
  -5. Bulletproof GC against SIGALRM
  +   4. Use a cache expiry database for more efficient GC (Jeremy Wohl)
   
  -Chuck Murcko <chuck@topsail.org> 15 April 1997
  +   5. Bulletproof GC against SIGALRM
   
  -*/
  +   Chuck Murcko <chuck@topsail.org> 15 April 1997
  +
  + */
   
   #define TESTING	0
   #undef EXPLAIN
  @@ -100,17 +100,19 @@
   #include "httpd.h"
   #include "http_config.h"
   #include "http_protocol.h"
  -  
  +
   #include "explain.h"
   
   extern module MODULE_VAR_EXPORT proxy_module;
   
   
   /* for proxy_canonenc() */
  -enum enctype { enc_path, enc_search, enc_user, enc_fpath, enc_parm }; 
  - 
  -#define HDR_APP (0)	/* append header, for proxy_add_header() */
  -#define HDR_REP (1)	/* replace header, for proxy_add_header() */
  +enum enctype {
  +    enc_path, enc_search, enc_user, enc_fpath, enc_parm
  +};
  +
  +#define HDR_APP (0)		/* append header, for proxy_add_header() */
  +#define HDR_REP (1)		/* replace header, for proxy_add_header() */
   
   /* number of characters in the hash */
   #define HASH_LEN (22*2)
  @@ -128,19 +130,17 @@
   #define	DEFAULT_PROSPERO_PORT	1525	/* WARNING: conflict w/Oracle */
   
   /* Some WWW schemes and their default ports; this is basically /etc/services */
  -struct proxy_services
  -{
  +struct proxy_services {
       const char *scheme;
       int port;
   };
   
   /* static information about a remote proxy */
  -struct proxy_remote
  -{
  -    const char *scheme;    /* the schemes handled by this proxy, or '*' */
  -    const char *protocol;  /* the scheme used to talk to this proxy */
  -    const char *hostname;  /* the hostname of this proxy */
  -    int port;              /* the port for this proxy */
  +struct proxy_remote {
  +    const char *scheme;		/* the schemes handled by this proxy, or '*' */
  +    const char *protocol;	/* the scheme used to talk to this proxy */
  +    const char *hostname;	/* the hostname of this proxy */
  +    int port;			/* the port for this proxy */
   };
   
   struct proxy_alias {
  @@ -150,9 +150,9 @@
   
   struct dirconn_entry {
       char *name;
  -    struct in_addr addr,mask;
  +    struct in_addr addr, mask;
       struct hostent hostlist;
  -    int (*matcher)(struct dirconn_entry *This, request_rec *r);
  +    int (*matcher) (struct dirconn_entry * This, request_rec *r);
   };
   
   struct noproxy_entry {
  @@ -171,74 +171,70 @@
   #define DEFAULT_CACHE_LMFACTOR (0.1)
   
   /* static information about the local cache */
  -struct cache_conf
  -{
  -    const char *root;   /* the location of the cache directory */
  -    int space;          /* Maximum cache size (in 1024 bytes) */
  -    int maxexpire;      /* Maximum time to keep cached files in secs */
  -    int defaultexpire;  /* default time to keep cached file in secs */
  -    double lmfactor;    /* factor for estimating expires date */
  -    int gcinterval;     /* garbage collection interval, in seconds */
  -    int dirlevels;	/* Number of levels of subdirectories */
  -    int dirlength;	/* Length of subdirectory names */
  +struct cache_conf {
  +    const char *root;		/* the location of the cache directory */
  +    int space;			/* Maximum cache size (in 1024 bytes) */
  +    int maxexpire;		/* Maximum time to keep cached files in secs */
  +    int defaultexpire;		/* default time to keep cached file in secs */
  +    double lmfactor;		/* factor for estimating expires date */
  +    int gcinterval;		/* garbage collection interval, in seconds */
  +    int dirlevels;		/* Number of levels of subdirectories */
  +    int dirlength;		/* Length of subdirectory names */
   };
   
  -typedef struct
  -{
  -    struct cache_conf cache;  /* cache configuration */
  +typedef struct {
  +    struct cache_conf cache;	/* cache configuration */
       array_header *proxies;
       array_header *aliases;
       array_header *noproxies;
       array_header *dirconn;
       array_header *nocaches;
  -    char         *domain;    /* domain name to use in absence of a domain name in the request */
  -    int req;                 /* true if proxy requests are enabled */
  +    char *domain;		/* domain name to use in absence of a domain name in the request */
  +    int req;			/* true if proxy requests are enabled */
       int recv_buffer_size;
   } proxy_server_conf;
   
  -struct hdr_entry
  -{
  +struct hdr_entry {
       char *field;
       char *value;
   };
   
   /* caching information about a request */
  -struct cache_req
  -{
  -    request_rec *req;  /* the request */
  -    char *url;         /* the URL requested */
  -    char *filename;    /* name of the cache file, or NULL if no cache */
  -    char *tempfile;    /* name of the temporary file, of NULL if not caching */
  -    time_t ims;        /* if-modified-since date of request; -1 if no header */
  -    BUFF *fp;          /* the cache file descriptor if the file is cached
  -                          and may be returned, or NULL if the file is
  -                          not cached (or must be reloaded) */
  -    time_t expire;      /* calculated expire date of cached entity */
  -    time_t lmod;        /* last-modified date of cached entity */
  -    time_t date;        /* the date the cached file was last touched */
  -    int version;        /* update count of the file */
  -    unsigned int len;   /* content length */
  -    char *protocol;     /* Protocol, and major/minor number, e.g. HTTP/1.1 */
  -    int status;         /* the status of the cached file */
  -    char *resp_line;    /* the whole status like (protocol, code + message) */
  -    array_header *hdrs; /* the HTTP headers of the file */
  +struct cache_req {
  +    request_rec *req;		/* the request */
  +    char *url;			/* the URL requested */
  +    char *filename;		/* name of the cache file, or NULL if no cache */
  +    char *tempfile;		/* name of the temporary file, of NULL if not caching */
  +    time_t ims;			/* if-modified-since date of request; -1 if no header */
  +    BUFF *fp;			/* the cache file descriptor if the file is cached
  +				   and may be returned, or NULL if the file is
  +				   not cached (or must be reloaded) */
  +    time_t expire;		/* calculated expire date of cached entity */
  +    time_t lmod;		/* last-modified date of cached entity */
  +    time_t date;		/* the date the cached file was last touched */
  +    int version;		/* update count of the file */
  +    unsigned int len;		/* content length */
  +    char *protocol;		/* Protocol, and major/minor number, e.g. HTTP/1.1 */
  +    int status;			/* the status of the cached file */
  +    char *resp_line;		/* the whole status like (protocol, code + message) */
  +    array_header *hdrs;		/* the HTTP headers of the file */
   };
  -      
  +
   /* Function prototypes */
   
   /* proxy_cache.c */
   
   void proxy_cache_tidy(struct cache_req *c);
   int proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  -    struct cache_req **cr);
  +		      struct cache_req **cr);
   int proxy_cache_update(struct cache_req *c, array_header *resp_hdrs,
  -    const int is_HTTP1, int nocache);
  +		       const int is_HTTP1, int nocache);
   void proxy_garbage_coll(request_rec *r);
   
   /* proxy_connect.c */
   
  -int proxy_connect_handler(request_rec *r, struct cache_req *c, char *url, 
  -    const char *proxyhost, int proxyport);
  +int proxy_connect_handler(request_rec *r, struct cache_req *c, char *url,
  +			  const char *proxyhost, int proxyport);
   
   /* proxy_ftp.c */
   
  @@ -248,33 +244,33 @@
   /* proxy_http.c */
   
   int proxy_http_canon(request_rec *r, char *url, const char *scheme,
  -    int def_port);
  +		     int def_port);
   int proxy_http_handler(request_rec *r, struct cache_req *c, char *url,
  -    const char *proxyhost, int proxyport);
  +		       const char *proxyhost, int proxyport);
   
   /* proxy_util.c */
   
   int proxy_hex2c(const char *x);
   void proxy_c2hex(int ch, char *x);
   char *proxy_canonenc(pool *p, const char *x, int len, enum enctype t,
  -    int isenc);
  +		     int isenc);
   char *proxy_canon_netloc(pool *p, char **const urlp, char **userp,
  -    char **passwordp, char **hostp, int *port);
  +			 char **passwordp, char **hostp, int *port);
   char *proxy_date_canon(pool *p, char *x);
   array_header *proxy_read_headers(pool *p, char *buffer, int size, BUFF *f);
   long int proxy_send_fb(BUFF *f, request_rec *r, BUFF *f2, struct cache_req *c);
   struct hdr_entry *proxy_get_header(array_header *hdrs_arr, const char *name);
   struct hdr_entry *proxy_add_header(array_header *hdrs_arr, char *field,
  -    char *value, int rep);
  +				   char *value, int rep);
   void proxy_del_header(array_header *hdrs_arr, const char *field);
  -void proxy_send_headers(request_rec *r, const char *respline, 
  -    array_header *hdrs_arr);
  +void proxy_send_headers(request_rec *r, const char *respline,
  +			array_header *hdrs_arr);
   int proxy_liststr(const char *list, const char *val);
  -void proxy_hash(const char *it, char *val,int ndepth,int nlength);
  +void proxy_hash(const char *it, char *val, int ndepth, int nlength);
   int proxy_hex2sec(const char *x);
   void proxy_sec2hex(int t, char *y);
   void proxy_log_uerror(const char *routine, const char *file, const char *err,
  -    server_rec *s);
  +		      server_rec *s);
   BUFF *proxy_cache_error(struct cache_req *r);
   int proxyerror(request_rec *r, const char *message);
   const char *proxy_host2addr(const char *host, struct hostent *reqhp);
  @@ -284,4 +280,3 @@
   int proxy_is_word(struct dirconn_entry *This);
   int proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r);
   int proxy_garbage_init(server_rec *, pool *);
  -
  
  
  
  1.27      +274 -307  apachen/src/modules/proxy/proxy_cache.c
  
  Index: proxy_cache.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_cache.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- proxy_cache.c	1997/09/06 14:16:56	1.26
  +++ proxy_cache.c	1997/09/16 00:59:39	1.27
  @@ -68,23 +68,24 @@
   
   #define	abs(c)	((c) >= 0 ? (c) : -(c))
   
  -struct gc_ent
  -{
  +struct gc_ent {
       unsigned long int len;
       time_t expire;
  -    char file[HASH_LEN+1];
  +    char file[HASH_LEN + 1];
   
   };
   
  -static int
  -gcdiff(const void *ap, const void *bp)
  +static int gcdiff(const void *ap, const void *bp)
   {
  -    const struct gc_ent *a=*(const struct gc_ent * const *)ap;
  -    const struct gc_ent *b=*(const struct gc_ent * const *)bp;
  +    const struct gc_ent *a = *(const struct gc_ent * const *) ap;
  +    const struct gc_ent *b = *(const struct gc_ent * const *) bp;
   
  -    if (a->expire > b->expire) return 1;
  -    else if (a->expire < b->expire) return -1;
  -    else return 0;
  +    if (a->expire > b->expire)
  +	return 1;
  +    else if (a->expire < b->expire)
  +	return -1;
  +    else
  +	return 0;
   }
   
   static int curbytes, cachesize, every;
  @@ -94,91 +95,87 @@
   static mutex *garbage_mutex = NULL;
   
   
  -int
  -proxy_garbage_init(server_rec *r, pool *p)
  +int proxy_garbage_init(server_rec *r, pool *p)
   {
  -    if(!garbage_mutex)
  -        garbage_mutex = create_mutex(NULL);
  +    if (!garbage_mutex)
  +	garbage_mutex = create_mutex(NULL);
   
  -    return(0);
  +    return (0);
   }
   
   
  -static int sub_garbage_coll(request_rec *r,array_header *files,
  -			    const char *cachedir,const char *cachesubdir);
  +static int sub_garbage_coll(request_rec *r, array_header *files,
  +			    const char *cachedir, const char *cachesubdir);
   static void help_proxy_garbage_coll(request_rec *r);
   
   void proxy_garbage_coll(request_rec *r)
   {
       static int inside = 0;
   
  -    (void)acquire_mutex(garbage_mutex);
  -    if(inside == 1)
  -    {
  -        (void)release_mutex(garbage_mutex);
  -        return;
  +    (void) acquire_mutex(garbage_mutex);
  +    if (inside == 1) {
  +	(void) release_mutex(garbage_mutex);
  +	return;
       }
       else
  -        inside = 1;
  -    (void)release_mutex(garbage_mutex);
  +	inside = 1;
  +    (void) release_mutex(garbage_mutex);
   
       help_proxy_garbage_coll(r);
   
  -    (void)acquire_mutex(garbage_mutex);
  +    (void) acquire_mutex(garbage_mutex);
       inside = 0;
  -    (void)release_mutex(garbage_mutex);
  +    (void) release_mutex(garbage_mutex);
   }
   
   
   void help_proxy_garbage_coll(request_rec *r)
  -    {
  +{
       const char *cachedir;
       void *sconf = r->server->module_config;
       proxy_server_conf *pconf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  -    const struct cache_conf *conf=&pconf->cache;
  +    (proxy_server_conf *) get_module_config(sconf, &proxy_module);
  +    const struct cache_conf *conf = &pconf->cache;
       array_header *files;
       struct stat buf;
  -    struct gc_ent *fent,**elts;    
  +    struct gc_ent *fent, **elts;
       int i, timefd;
  -    static time_t lastcheck=BAD_DATE;  /* static data!!! */
  +    static time_t lastcheck = BAD_DATE;		/* static data!!! */
   
       cachedir = conf->root;
       cachesize = conf->space;
       every = conf->gcinterval;
   
  -    if (cachedir == NULL || every == -1) return;
  +    if (cachedir == NULL || every == -1)
  +	return;
       now = time(NULL);
  -    if (now != -1 && lastcheck != BAD_DATE && now < lastcheck + every) return;
  +    if (now != -1 && lastcheck != BAD_DATE && now < lastcheck + every)
  +	return;
   
  -    block_alarms();	/* avoid SIGALRM on big cache cleanup */
  +    block_alarms();		/* avoid SIGALRM on big cache cleanup */
   
       filename = palloc(r->pool, strlen(cachedir) + HASH_LEN + 2);
       strcpy(filename, cachedir);
       strcat(filename, "/.time");
  -    if (stat(filename, &buf) == -1) /* does not exist */
  -    {
  -	if (errno != ENOENT)
  -	{
  +    if (stat(filename, &buf) == -1) {	/* does not exist */
  +	if (errno != ENOENT) {
   	    proxy_log_uerror("stat", filename, NULL, r->server);
   	    unblock_alarms();
   	    return;
   	}
  -	if ((timefd = creat(filename, 0666)) == -1)
  -	{
  +	if ((timefd = creat(filename, 0666)) == -1) {
   	    if (errno != EEXIST)
   		proxy_log_uerror("creat", filename, NULL, r->server);
   	    else
  -		lastcheck = abs(now);  /* someone else got in there */
  +		lastcheck = abs(now);	/* someone else got in there */
   	    unblock_alarms();
   	    return;
   	}
   	close(timefd);
  -    } else
  -    {
  -	lastcheck = buf.st_mtime;  /* save the time */
  -	if (now < lastcheck + every)
  -	{
  +    }
  +    else {
  +	lastcheck = buf.st_mtime;	/* save the time */
  +	if (now < lastcheck + every) {
   	    unblock_alarms();
   	    return;
   	}
  @@ -189,27 +186,24 @@
       curblocks = 0;
       curbytes = 0;
   
  -    sub_garbage_coll(r,files,cachedir,"/");
  +    sub_garbage_coll(r, files, cachedir, "/");
   
  -    if (curblocks < cachesize || curblocks + curbytes <= cachesize)
  -    {
  +    if (curblocks < cachesize || curblocks + curbytes <= cachesize) {
   	unblock_alarms();
   	return;
       }
   
       qsort(files->elts, files->nelts, sizeof(struct gc_ent *), gcdiff);
   
  -    elts = (struct gc_ent **)files->elts;
  -    for (i=0; i < files->nelts; i++)
  -    {
  +    elts = (struct gc_ent **) files->elts;
  +    for (i = 0; i < files->nelts; i++) {
   	fent = elts[i];
   	sprintf(filename, "%s%s", cachedir, fent->file);
  -	Explain3("GC Unlinking %s (expiry %ld, now %ld)",filename,fent->expire,now);
  +	Explain3("GC Unlinking %s (expiry %ld, now %ld)", filename, fent->expire, now);
   #if TESTING
  -	fprintf(stderr,"Would unlink %s\n",filename);
  +	fprintf(stderr, "Would unlink %s\n", filename);
   #else
  -	if (unlink(filename) == -1)
  -	{
  +	if (unlink(filename) == -1) {
   	    if (errno != ENOENT)
   		proxy_log_uerror("unlink", filename, NULL, r->server);
   	}
  @@ -218,8 +212,7 @@
   	{
   	    curblocks -= fent->len >> 10;
   	    curbytes -= fent->len & 0x3FF;
  -	    if (curbytes < 0)
  -	    {
  +	    if (curbytes < 0) {
   		curbytes += 1024;
   		curblocks--;
   	    }
  @@ -230,13 +223,13 @@
       unblock_alarms();
   }
   
  -static int sub_garbage_coll(request_rec *r,array_header *files,
  -			     const char *cachebasedir,const char *cachesubdir)
  +static int sub_garbage_coll(request_rec *r, array_header *files,
  +			  const char *cachebasedir, const char *cachesubdir)
   {
       char line[27];
       char cachedir[HUGE_STRING_LEN];
       struct stat buf;
  -    int fd,i;
  +    int fd, i;
       DIR *dir;
   #if defined(NEXT) || defined(WIN32)
       struct DIR_TYPE *ent;
  @@ -244,101 +237,92 @@
       struct dirent *ent;
   #endif
       struct gc_ent *fent;
  -    int nfiles=0;
  +    int nfiles = 0;
   
  -    ap_snprintf(cachedir, sizeof(cachedir), "%s%s",cachebasedir,cachesubdir);
  -    Explain1("GC Examining directory %s",cachedir);
  +    ap_snprintf(cachedir, sizeof(cachedir), "%s%s", cachebasedir, cachesubdir);
  +    Explain1("GC Examining directory %s", cachedir);
       dir = opendir(cachedir);
  -    if (dir == NULL)
  -    {
  +    if (dir == NULL) {
   	proxy_log_uerror("opendir", cachedir, NULL, r->server);
   	return 0;
       }
   
  -    while ((ent = readdir(dir)) != NULL)
  -    {
  -	if (ent->d_name[0] == '.') continue;
  +    while ((ent = readdir(dir)) != NULL) {
  +	if (ent->d_name[0] == '.')
  +	    continue;
   	sprintf(filename, "%s%s", cachedir, ent->d_name);
  -	Explain1("GC Examining file %s",filename);
  +	Explain1("GC Examining file %s", filename);
   /* is it a temporary file? */
  -	if (strncmp(ent->d_name, "tmp", 3) == 0)
  -	{
  +	if (strncmp(ent->d_name, "tmp", 3) == 0) {
   /* then stat it to see how old it is; delete temporary files > 1 day old */
  -	    if (stat(filename, &buf) == -1)
  -	    {
  +	    if (stat(filename, &buf) == -1) {
   		if (errno != ENOENT)
   		    proxy_log_uerror("stat", filename, NULL, r->server);
  -	    } else if (now != -1 && buf.st_atime < now - SEC_ONE_DAY &&
  -		       buf.st_mtime < now - SEC_ONE_DAY)
  -		{
  -		Explain1("GC unlink %s",filename);
  +	    }
  +	    else if (now != -1 && buf.st_atime < now - SEC_ONE_DAY &&
  +		     buf.st_mtime < now - SEC_ONE_DAY) {
  +		Explain1("GC unlink %s", filename);
   #if TESTING
  -		fprintf(stderr,"Would unlink %s\n",filename);
  +		fprintf(stderr, "Would unlink %s\n", filename);
   #else
   		unlink(filename);
   #endif
  -		}
  +	    }
   	    continue;
   	}
   	++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; */
   
   /* read the file */
   	fd = open(filename, O_RDONLY | O_BINARY);
  -	if (fd == -1)
  -	{
  -	    if (errno  != ENOENT) proxy_log_uerror("open", filename,NULL,
  -		r->server);
  +	if (fd == -1) {
  +	    if (errno != ENOENT)
  +		proxy_log_uerror("open", filename, NULL,
  +				 r->server);
   	    continue;
   	}
  -	if (fstat(fd, &buf) == -1)
  -	{
  +	if (fstat(fd, &buf) == -1) {
   	    proxy_log_uerror("fstat", filename, NULL, r->server);
   	    close(fd);
   	    continue;
   	}
  -	if(S_ISDIR(buf.st_mode))
  -	    {
  +	if (S_ISDIR(buf.st_mode)) {
   	    char newcachedir[HUGE_STRING_LEN];
   	    close(fd);
   	    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);
   #endif
   		--nfiles;
  -		}
  -	    continue;
   	    }
  -	    
  +	    continue;
  +	}
  +
   	i = read(fd, line, 26);
  -	if (i == -1)
  -	{
  +	if (i == -1) {
   	    proxy_log_uerror("read", filename, NULL, r->server);
   	    close(fd);
   	    continue;
   	}
   	close(fd);
   	line[i] = '\0';
  -	expire = proxy_hex2sec(line+18);
  +	expire = proxy_hex2sec(line + 18);
   	if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&&") ||
  -	  expire == BAD_DATE)
  -	{
  +	    expire == BAD_DATE) {
   	    /* bad file */
   	    if (now != -1 && buf.st_atime > now + SEC_ONE_DAY &&
  -		buf.st_mtime > now + SEC_ONE_DAY)
  -	    {
  +		buf.st_mtime > now + SEC_ONE_DAY) {
   		log_error("proxy: deleting bad cache file", r->server);
   #if TESTING
  -		fprintf(stderr,"Would unlink bad file %s\n",filename);
  +		fprintf(stderr, "Would unlink bad file %s\n", filename);
   #else
   		unlink(filename);
   #endif
  @@ -357,15 +341,14 @@
   	fent = palloc(r->pool, sizeof(struct gc_ent));
   	fent->len = buf.st_size;
   	fent->expire = expire;
  -	strcpy(fent->file,cachesubdir);
  +	strcpy(fent->file, cachesubdir);
   	strcat(fent->file, ent->d_name);
  -	*(struct gc_ent **)push_array(files) = fent;
  +	*(struct gc_ent **) push_array(files) = fent;
   
   /* accumulate in blocks, to cope with directories > 4Gb */
  -	curblocks += buf.st_size >> 10; /* Kbytes */
  +	curblocks += buf.st_size >> 10;		/* Kbytes */
   	curbytes += buf.st_size & 0x3FF;
  -	if (curbytes >= 1024)
  -	{
  +	if (curbytes >= 1024) {
   	    curbytes -= 1024;
   	    curblocks++;
   	}
  @@ -383,8 +366,7 @@
    *         0 on failure (bad file or wrong URL)
    *        -1 on UNIX error
    */
  -static int
  -rdcache(pool *p, BUFF *cachefp, struct cache_req *c)
  +static int rdcache(pool *p, BUFF *cachefp, struct cache_req *c)
   {
       char urlbuff[1034], *strp;
       int len;
  @@ -394,48 +376,54 @@
    * dates are stored as hex seconds since 1970
    */
       len = bgets(urlbuff, 1034, cachefp);
  -    if (len == -1) return -1;
  -    if (len == 0 || urlbuff[len-1] != '\n') return 0;
  -    urlbuff[len-1] = '\0';
  +    if (len == -1)
  +	return -1;
  +    if (len == 0 || urlbuff[len - 1] != '\n')
  +	return 0;
  +    urlbuff[len - 1] = '\0';
   
       if (!checkmask(urlbuff,
  -      "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&"))
  +		   "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&"))
   	return 0;
   
       c->date = proxy_hex2sec(urlbuff);
  -    c->lmod = proxy_hex2sec(urlbuff+9);
  -    c->expire = proxy_hex2sec(urlbuff+18);
  -    c->version = proxy_hex2sec(urlbuff+27);
  -    c->len = proxy_hex2sec(urlbuff+36);
  +    c->lmod = proxy_hex2sec(urlbuff + 9);
  +    c->expire = proxy_hex2sec(urlbuff + 18);
  +    c->version = proxy_hex2sec(urlbuff + 27);
  +    c->len = proxy_hex2sec(urlbuff + 36);
   
   /* check that we have the same URL */
       len = bgets(urlbuff, 1034, cachefp);
  -    if (len == -1) return -1;
  +    if (len == -1)
  +	return -1;
       if (len == 0 || strncmp(urlbuff, "X-URL: ", 7) != 0 ||
  -	urlbuff[len-1] != '\n')
  +	urlbuff[len - 1] != '\n')
  +	return 0;
  +    urlbuff[len - 1] = '\0';
  +    if (strcmp(urlbuff + 7, c->url) != 0)
   	return 0;
  -    urlbuff[len-1] = '\0';
  -    if (strcmp(urlbuff+7, c->url) != 0) return 0;
   
   /* What follows is the message */
       len = bgets(urlbuff, 1034, cachefp);
  -    if (len == -1) return -1;
  -    if (len == 0 || urlbuff[len-1] != '\n') return 0;
  +    if (len == -1)
  +	return -1;
  +    if (len == 0 || urlbuff[len - 1] != '\n')
  +	return 0;
       urlbuff[--len] = '\0';
   
       c->resp_line = pstrdup(p, urlbuff);
       strp = strchr(urlbuff, ' ');
  -    if (strp == NULL) return 0;
  +    if (strp == NULL)
  +	return 0;
   
       c->status = atoi(strp);
       c->hdrs = proxy_read_headers(p, urlbuff, 1034, cachefp);
  -    if (c->hdrs == NULL) return -1;
  -    if (c->len != -1) /* add a content-length header */
  -    {
  +    if (c->hdrs == NULL)
  +	return -1;
  +    if (c->len != -1) {		/* add a content-length header */
   	struct hdr_entry *q;
   	q = proxy_get_header(c->hdrs, "Content-Length");
  -	if (q == NULL)
  -	{
  +	if (q == NULL) {
   	    strp = palloc(p, 15);
   	    ap_snprintf(strp, 15, "%u", c->len);
   	    proxy_add_header(c->hdrs, "Content-Length", strp, HDR_REP);
  @@ -459,19 +447,18 @@
    *         if last modified after if-modified-since then add
    *            last modified date to request
    */
  -int
  -proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  -	     struct cache_req **cr)
  +int proxy_cache_check(request_rec *r, char *url, struct cache_conf *conf,
  +		      struct cache_req **cr)
   {
       char hashfile[66], *imstr, *pragma, *p, *auth;
       struct cache_req *c;
       time_t now;
       BUFF *cachefp;
       int cfd, i;
  -    const long int zero=0L;
  +    const long int zero = 0L;
       void *sconf = r->server->module_config;
       proxy_server_conf *pconf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  +    (proxy_server_conf *) get_module_config(sconf, &proxy_module);
   
       c = pcalloc(r->pool, sizeof(struct cache_req));
       *cr = c;
  @@ -481,17 +468,16 @@
   /* get the If-Modified-Since date of the request */
       c->ims = BAD_DATE;
       imstr = table_get(r->headers_in, "If-Modified-Since");
  -    if (imstr != NULL)
  -    {
  +    if (imstr != NULL) {
   /* this may modify the value in the original table */
   	imstr = proxy_date_canon(r->pool, imstr);
   	c->ims = parseHTTPdate(imstr);
  -	if (c->ims == BAD_DATE)  /* bad or out of range date; remove it */
  +	if (c->ims == BAD_DATE)	/* bad or out of range date; remove it */
   	    table_set(r->headers_in, "If-Modified-Since", NULL);
       }
   
   /* find the filename for this cache entry */
  -    proxy_hash(url, hashfile,pconf->cache.dirlevels,pconf->cache.dirlength);
  +    proxy_hash(url, hashfile, pconf->cache.dirlevels, pconf->cache.dirlength);
       if (conf->root != NULL)
   	c->filename = pstrcat(r->pool, conf->root, "/", hashfile, NULL);
       else
  @@ -501,38 +487,35 @@
   /* find out about whether the request can access the cache */
       pragma = table_get(r->headers_in, "Pragma");
       auth = table_get(r->headers_in, "Authorization");
  -    Explain5("Request for %s, pragma=%s, auth=%s, ims=%ld, imstr=%s",url,
  -      pragma,auth,c->ims,imstr);
  +    Explain5("Request for %s, pragma=%s, auth=%s, ims=%ld, imstr=%s", url,
  +	     pragma, auth, c->ims, imstr);
       if (c->filename != NULL && r->method_number == M_GET &&
   	strlen(url) < 1024 && !proxy_liststr(pragma, "no-cache") &&
  -	    auth == NULL)
  -    {
  -        Explain1("Check file %s",c->filename);
  +	auth == NULL) {
  +	Explain1("Check file %s", c->filename);
   	cfd = open(c->filename, O_RDWR | O_BINARY);
  -	if (cfd != -1)
  -	{
  +	if (cfd != -1) {
   	    note_cleanups_for_fd(r->pool, cfd);
   	    cachefp = bcreate(r->pool, B_RD | B_WR);
   	    bpushfd(cachefp, cfd, cfd);
  -	} else if (errno != ENOENT)
  +	}
  +	else if (errno != ENOENT)
   	    proxy_log_uerror("open", c->filename,
  -		"proxy: error opening cache file", r->server);
  +			     "proxy: error opening cache file", r->server);
   #ifdef EXPLAIN
   	else
  -	    Explain1("File %s not found",c->filename);
  +	    Explain1("File %s not found", c->filename);
   #endif
       }
  -    
  -    if (cachefp != NULL)
  -    {
  +
  +    if (cachefp != NULL) {
   	i = rdcache(r->pool, cachefp, c);
   	if (i == -1)
   	    proxy_log_uerror("read", c->filename,
  -		"proxy: error reading cache file", r->server);
  +			     "proxy: error reading cache file", r->server);
   	else if (i == 0)
   	    log_error("proxy: bad cache file", r->server);
  -	if (i != 1)
  -	{
  +	if (i != 1) {
   	    pclosef(r->pool, cachefp->fd);
   	    cachefp = NULL;
   	}
  @@ -542,23 +525,21 @@
       /* FIXME: Shouldn't we check the URL somewhere? */
       now = time(NULL);
   /* Ok, have we got some un-expired data? */
  -    if (cachefp != NULL && c->expire != BAD_DATE && now < c->expire)
  -    {
  -        Explain0("Unexpired data available");
  +    if (cachefp != NULL && c->expire != BAD_DATE && now < c->expire) {
  +	Explain0("Unexpired data available");
   /* check IMS */
  -	if (c->lmod != BAD_DATE && c->ims != BAD_DATE && c->ims >= c->lmod)
  -	{
  +	if (c->lmod != BAD_DATE && c->ims != BAD_DATE && c->ims >= c->lmod) {
   /* has the cached file changed since this request? */
  -	    if (c->date == BAD_DATE || c->date > c->ims)
  -	    {
  +	    if (c->date == BAD_DATE || c->date > c->ims) {
   /* No, but these header values may have changed, so we send them with the
    * 304 response
    */
  -	    /* CHECKME: surely this was wrong? (Ben)
  -		p = table_get(r->headers_in, "Expires");
  -		*/
  +		/* CHECKME: surely this was wrong? (Ben)
  +		   p = table_get(r->headers_in, "Expires");
  +		 */
   		p = table_get(c->hdrs, "Expires");
  -		if (p != NULL) 	table_set(r->headers_out, "Expires", p);
  +		if (p != NULL)
  +		    table_set(r->headers_out, "Expires", p);
   	    }
   	    pclosef(r->pool, cachefp->fd);
   	    Explain0("Use local copy, cached file hasn't changed");
  @@ -576,7 +557,8 @@
   	}
   	bsetopt(r->connection->client, BO_BYTECT, &zero);
   	r->sent_bodyct = 1;
  -	if (!r->header_only) proxy_send_fb (cachefp, r, NULL, NULL);
  +	if (!r->header_only)
  +	    proxy_send_fb(cachefp, r, NULL, NULL);
   	pclosef(r->pool, cachefp->fd);
   	return OK;
       }
  @@ -585,21 +567,19 @@
    * request, then add an If-Modified-Since
    */
   
  -    if (cachefp != NULL && c->lmod != BAD_DATE && !r->header_only)
  -    {
  +    if (cachefp != NULL && c->lmod != BAD_DATE && !r->header_only) {
   /*
    * 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)
  -	{
  +	if (c->ims == BAD_DATE || c->ims < c->lmod) {
   	    struct hdr_entry *q;
   
   	    q = proxy_get_header(c->hdrs, "Last-Modified");
   
   	    if (q != NULL && q->value != NULL)
   		table_set(r->headers_in, "If-Modified-Since",
  -			  (char *)q->value);
  +			  (char *) q->value);
   	}
       }
       c->fp = cachefp;
  @@ -621,11 +601,10 @@
    *  from the cache, maybe updating the header line
    *  otherwise, delete the old cached file and open a new temporary file
    */
  -int
  -proxy_cache_update(struct cache_req *c, array_header *resp_hdrs,
  -                   const int is_HTTP1, int nocache)
  +int proxy_cache_update(struct cache_req *c, array_header *resp_hdrs,
  +		       const int is_HTTP1, int nocache)
   {
  -    request_rec *r=c->req;
  +    request_rec *r = c->req;
       char *p;
       int i;
       struct hdr_entry *expire, *dates, *lmods, *clen;
  @@ -633,8 +612,8 @@
       char buff[46];
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  -    const long int zero=0L;
  +    (proxy_server_conf *) get_module_config(sconf, &proxy_module);
  +    const long int zero = 0L;
   
       c->tempfile = NULL;
   
  @@ -643,23 +622,24 @@
    * read it
    */
       expire = proxy_get_header(resp_hdrs, "Expires");
  -    if (expire != NULL) expc = parseHTTPdate(expire->value);
  -    else expc = BAD_DATE;
  +    if (expire != NULL)
  +	expc = parseHTTPdate(expire->value);
  +    else
  +	expc = BAD_DATE;
   
   /*
    * read the last-modified date; if the date is bad, then delete it
    */
       lmods = proxy_get_header(resp_hdrs, "Last-Modified");
  -    if (lmods != NULL)
  -    {
  +    if (lmods != NULL) {
   	lmod = parseHTTPdate(lmods->value);
  -	if (lmod == BAD_DATE)
  -	{
  +	if (lmod == BAD_DATE) {
   /* kill last modified date */
   	    lmods->value = NULL;
   	    lmods = NULL;
   	}
  -    } else
  +    }
  +    else
   	lmod = BAD_DATE;
   
   /*
  @@ -677,18 +657,16 @@
   	(r->status == 200 && lmods == NULL && is_HTTP1) ||
   	r->header_only ||
   	table_get(r->headers_in, "Authorization") != NULL ||
  -	nocache)
  -    {
  -	Explain1("Response is not cacheable, unlinking %s",c->filename);
  +	nocache) {
  +	Explain1("Response is not cacheable, unlinking %s", c->filename);
   /* close the file */
  -	if (c->fp != NULL)
  -	{
  +	if (c->fp != NULL) {
   	    pclosef(r->pool, c->fp->fd);
   	    c->fp = NULL;
   	}
   /* delete the previously cached file */
   	unlink(c->filename);
  -	return DECLINED; /* send data to client but not cache */
  +	return DECLINED;	/* send data to client but not cache */
       }
   
   /* otherwise, we are going to cache the response */
  @@ -696,13 +674,14 @@
    * Read the date. Generate one if one is not supplied
    */
       dates = proxy_get_header(resp_hdrs, "Date");
  -    if (dates != NULL) date = parseHTTPdate(dates->value);
  -    else date = BAD_DATE;
  -	
  +    if (dates != NULL)
  +	date = parseHTTPdate(dates->value);
  +    else
  +	date = BAD_DATE;
  +
       now = time(NULL);
   
  -    if (date == BAD_DATE) /* No, or bad date */
  -    {
  +    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
    */
  @@ -721,17 +700,16 @@
   	Explain0("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)
  -	{
  +    if (lmod == BAD_DATE && c->fp != NULL) {
   	lmod = c->lmod;
   	Explain0("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 */
  -    {
  +    if (expire == NULL && c->fp != NULL) {	/* no expiry data sent in response */
   	expire = proxy_get_header(c->hdrs, "Expires");
  -	if (expire != NULL) expc = parseHTTPdate(expire->value);
  +	if (expire != NULL)
  +	    expc = parseHTTPdate(expire->value);
       }
   /* so we now have the expiry date */
   /* if no expiry date then
  @@ -740,60 +718,59 @@
    *   else
    *      expire date = now + defaultexpire
    */
  -    Explain1("Expiry date is %ld",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 = abs(now) + (int)x;
  -	} else
  +    Explain1("Expiry date is %ld", 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 = abs(now) + (int) x;
  +	}
  +	else
   	    expc = abs(now) + conf->cache.defaultexpire;
  -	Explain1("Expiry date calculated %ld",expc);
  +	Explain1("Expiry date calculated %ld", expc);
       }
   
   /* get the content-length header */
       clen = proxy_get_header(c->hdrs, "Content-Length");
  -    if (clen == NULL) c->len = -1;
  -    else c->len = atoi(clen->value);
  +    if (clen == NULL)
  +	c->len = -1;
  +    else
  +	c->len = atoi(clen->value);
   
       proxy_sec2hex(date, buff);
       buff[8] = ' ';
  -    proxy_sec2hex(lmod, buff+9);
  +    proxy_sec2hex(lmod, buff + 9);
       buff[17] = ' ';
  -    proxy_sec2hex(expc, buff+18);
  +    proxy_sec2hex(expc, buff + 18);
       buff[26] = ' ';
  -    proxy_sec2hex(c->version++, buff+27);
  +    proxy_sec2hex(c->version++, buff + 27);
       buff[35] = ' ';
  -    proxy_sec2hex(c->len, buff+36);
  +    proxy_sec2hex(c->len, buff + 36);
       buff[44] = '\n';
       buff[45] = '\0';
   
   /* if file not modified */
  -    if (r->status == 304)
  -    {
  -	if (c->ims != BAD_DATE && lmod != BAD_DATE && lmod <= c->ims)
  -	{
  +    if (r->status == 304) {
  +	if (c->ims != BAD_DATE && lmod != BAD_DATE && lmod <= c->ims) {
   /* set any changed headers somehow */
   /* update dates and version, but not content-length */
  -	    if (lmod != c->lmod || expc != c->expire || date != c->date)
  -	    {
  -		off_t curpos=lseek(c->fp->fd, 0, SEEK_SET);
  +	    if (lmod != c->lmod || expc != c->expire || date != c->date) {
  +		off_t curpos = lseek(c->fp->fd, 0, SEEK_SET);
   		if (curpos == -1)
   		    proxy_log_uerror("lseek", c->filename,
  -			       "proxy: error seeking on cache file",r->server);
  +			   "proxy: error seeking on cache file", r->server);
   		else if (write(c->fp->fd, buff, 35) == -1)
   		    proxy_log_uerror("write", c->filename,
  -			       "proxy: error updating cache file", r->server);
  +			     "proxy: error updating cache file", r->server);
   	    }
   	    pclosef(r->pool, c->fp->fd);
   	    Explain0("Remote document not modified, use local copy");
   	    /* CHECKME: Is this right? Shouldn't we check IMS again here? */
   	    return USE_LOCAL_COPY;
  -	} else
  -	{
  +	}
  +	else {
   /* return the whole document */
   	    Explain0("Remote document updated, sending");
   	    r->status_line = strchr(c->resp_line, ' ') + 1;
  @@ -805,63 +782,60 @@
   	    }
   	    bsetopt(r->connection->client, BO_BYTECT, &zero);
   	    r->sent_bodyct = 1;
  -	    if (!r->header_only) proxy_send_fb (c->fp, r, NULL, NULL);
  +	    if (!r->header_only)
  +		proxy_send_fb(c->fp, r, NULL, NULL);
   /* set any changed headers somehow */
   /* update dates and version, but not content-length */
  -	    if (lmod != c->lmod || expc != c->expire || date != c->date)
  -	    {
  -		off_t curpos=lseek(c->fp->fd, 0, SEEK_SET);
  +	    if (lmod != c->lmod || expc != c->expire || date != c->date) {
  +		off_t curpos = lseek(c->fp->fd, 0, SEEK_SET);
   
   		if (curpos == -1)
   		    proxy_log_uerror("lseek", c->filename,
  -			       "proxy: error seeking on cache file",r->server);
  +			   "proxy: error seeking on cache file", r->server);
   		else if (write(c->fp->fd, buff, 35) == -1)
   		    proxy_log_uerror("write", c->filename,
  -			       "proxy: error updating cache file", r->server);
  +			     "proxy: error updating cache file", r->server);
   	    }
   	    pclosef(r->pool, c->fp->fd);
   	    return OK;
   	}
       }
  -/* new or modified file */	    
  -    if (c->fp != NULL)
  -    {
  +/* new or modified file */
  +    if (c->fp != NULL) {
   	pclosef(r->pool, c->fp->fd);
   	c->fp->fd = -1;
       }
       c->version = 0;
  -    proxy_sec2hex(0, buff+27);
  +    proxy_sec2hex(0, buff + 27);
       buff[35] = ' ';
   
   /* open temporary file */
   #define TMPFILESTR	"/tmpXXXXXX"
       if (conf->cache.root == NULL)
  -        return DECLINED;
  -    c->tempfile=palloc(r->pool,strlen(conf->cache.root)+sizeof(TMPFILESTR));
  -    strcpy(c->tempfile,conf->cache.root);
  -    strcat(c->tempfile,TMPFILESTR);
  +	return DECLINED;
  +    c->tempfile = 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);
       if (p == NULL)
  -        return DECLINED;
  +	return DECLINED;
   
  -    Explain1("Create temporary file %s",c->tempfile);
  +    Explain1("Create temporary file %s", c->tempfile);
   
       i = open(c->tempfile, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0622);
  -    if (i == -1)
  -    {
  +    if (i == -1) {
   	proxy_log_uerror("open", c->tempfile,
  -	    "proxy: error creating cache file", r->server);
  +			 "proxy: error creating cache file", r->server);
   	return DECLINED;
       }
       note_cleanups_for_fd(r->pool, i);
       c->fp = bcreate(r->pool, B_WR);
       bpushfd(c->fp, -1, i);
   
  -    if (bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1)
  -    {
  +    if (bvputs(c->fp, buff, "X-URL: ", c->url, "\n", NULL) == -1) {
   	proxy_log_uerror("write", c->tempfile,
  -	    "proxy: error writing cache file", r->server);
  +			 "proxy: error writing cache file", r->server);
   	pclosef(r->pool, c->fp->fd);
   	unlink(c->tempfile);
   	c->fp = NULL;
  @@ -869,32 +843,30 @@
       return DECLINED;
   }
   
  -void
  -proxy_cache_tidy(struct cache_req *c)
  +void proxy_cache_tidy(struct cache_req *c)
   {
  -    server_rec *s=c->req->server;
  +    server_rec *s = c->req->server;
       long int bc;
   
  -    if (c->fp == NULL) return;
  +    if (c->fp == NULL)
  +	return;
   
       bgetopt(c->req->connection->client, BO_BYTECT, &bc);
   
  -    if (c->len != -1)
  -    {
  +    if (c->len != -1) {
   /* file lengths don't match; don't cache it */
  -	if (bc != c->len)
  -	{
  -	    pclosef(c->req->pool, c->fp->fd);  /* no need to flush */
  +	if (bc != c->len) {
  +	    pclosef(c->req->pool, c->fp->fd);	/* no need to flush */
   	    unlink(c->tempfile);
   	    return;
   	}
  -    } else
  -    if (c->req->connection->aborted) {
  -	    pclosef(c->req->pool, c->fp->fd);  /* no need to flush */
  -	    unlink(c->tempfile);
  -	    return;
  -    } else 
  -    {
  +    }
  +    else if (c->req->connection->aborted) {
  +	pclosef(c->req->pool, c->fp->fd);	/* no need to flush */
  +	unlink(c->tempfile);
  +	return;
  +    }
  +    else {
   /* update content-length of file */
   	char buff[9];
   	off_t curpos;
  @@ -905,72 +877,67 @@
   	curpos = lseek(c->fp->fd, 36, SEEK_SET);
   	if (curpos == -1)
   	    proxy_log_uerror("lseek", c->tempfile,
  -		"proxy: error seeking on cache file", s);
  +			     "proxy: error seeking on cache file", s);
   	else if (write(c->fp->fd, buff, 8) == -1)
   	    proxy_log_uerror("write", c->tempfile,
  -		"proxy: error updating cache file", s);
  +			     "proxy: error updating cache file", s);
       }
   
  -    if (bflush(c->fp) == -1)
  -    {
  +    if (bflush(c->fp) == -1) {
   	proxy_log_uerror("write", c->tempfile,
  -	    "proxy: error writing to cache file", s);
  +			 "proxy: error writing to cache file", s);
   	pclosef(c->req->pool, c->fp->fd);
   	unlink(c->tempfile);
   	return;
       }
   
  -    if (pclosef(c->req->pool, c->fp->fd) == -1)
  -    {
  +    if (pclosef(c->req->pool, c->fp->fd) == -1) {
   	proxy_log_uerror("close", c->tempfile,
  -	    "proxy: error closing cache file", s);
  +			 "proxy: error closing cache file", s);
   	unlink(c->tempfile);
   	return;
       }
   
  -    if (unlink(c->filename) == -1 && errno != ENOENT)
  -    {
  +    if (unlink(c->filename) == -1 && errno != ENOENT) {
   	proxy_log_uerror("unlink", c->filename,
  -		   "proxy: error deleting old cache file", s);
  -    } else
  -	{
  +			 "proxy: error deleting old cache file", s);
  +    }
  +    else {
   	char *p;
  -	proxy_server_conf *conf=
  -	  (proxy_server_conf *)get_module_config(s->module_config,&proxy_module);
  +	proxy_server_conf *conf =
  +	(proxy_server_conf *) get_module_config(s->module_config, &proxy_module);
   
  -	for(p=c->filename+strlen(conf->cache.root)+1 ; ; )
  -	    {
  -	    p=strchr(p,'/');
  -	    if(!p)
  +	for (p = c->filename + strlen(conf->cache.root) + 1;;) {
  +	    p = strchr(p, '/');
  +	    if (!p)
   		break;
  -	    *p='\0';
  +	    *p = '\0';
   #ifdef WIN32
  -	    if(mkdir(c->filename) < 0 && errno != EEXIST)
  +	    if (mkdir(c->filename) < 0 && errno != EEXIST)
   #else
  -	    if(mkdir(c->filename,S_IREAD|S_IWRITE|S_IEXEC) < 0 && errno != EEXIST)
  +	    if (mkdir(c->filename, S_IREAD | S_IWRITE | S_IEXEC) < 0 && errno != EEXIST)
   #endif /* WIN32 */
  -		proxy_log_uerror("mkdir",c->filename,
  -		    "proxy: error creating cache directory",s);
  -	    *p='/';
  +		proxy_log_uerror("mkdir", c->filename,
  +				 "proxy: error creating cache directory", s);
  +	    *p = '/';
   	    ++p;
  -	    }
  +	}
   #if defined(__EMX__) || defined(WIN32)
  -        /* Under OS/2 use rename. */            
  -        if (rename(c->tempfile, c->filename) == -1)
  -            proxy_log_uerror("rename", c->filename,
  -		"proxy: error renaming cache file", s);
  -}
  -#else            
  +	/* Under OS/2 use rename. */
  +	if (rename(c->tempfile, c->filename) == -1)
  +	    proxy_log_uerror("rename", c->filename,
  +			     "proxy: error renaming cache file", s);
  +    }
  +#else
   
   	if (link(c->tempfile, c->filename) == -1)
   	    proxy_log_uerror("link", c->filename,
  -		"proxy: error linking cache file", s);
  -	}
  +			     "proxy: error linking cache file", s);
  +    }
   
       if (unlink(c->tempfile) == -1)
   	proxy_log_uerror("unlink", c->tempfile,
  -	    "proxy: error deleting temp file",s);
  +			 "proxy: error deleting temp file", s);
   #endif
   
   }
  -
  
  
  
  1.18      +94 -100   apachen/src/modules/proxy/proxy_connect.c
  
  Index: proxy_connect.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_connect.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- proxy_connect.c	1997/09/06 14:16:56	1.17
  +++ proxy_connect.c	1997/09/16 00:59:39	1.18
  @@ -57,7 +57,7 @@
   #include "http_main.h"
   
   #ifdef HAVE_BSTRING_H
  -#include <bstring.h>            /* for IRIX, FD_SET calls bzero() */
  +#include <bstring.h>		/* for IRIX, FD_SET calls bzero() */
   #endif
   
   DEF_Explain
  @@ -84,61 +84,57 @@
    * FIXME: this doesn't log the number of bytes sent, but
    *        that may be okay, since the data is supposed to
    *        be transparent. In fact, this doesn't log at all
  - *	  yet. 8^)
  + *        yet. 8^)
    * FIXME: doesn't check any headers initally sent from the
    *        client.
    * FIXME: should allow authentication, but hopefully the
    *        generic proxy authentication is good enough.
    * FIXME: no check for r->assbackwards, whatever that is.
  - */ 
  - 
  -int
  -proxy_connect_handler(request_rec *r, struct cache_req *c, char *url,
  -    const char *proxyhost, int proxyport)
  + */
  +
  +int proxy_connect_handler(request_rec *r, struct cache_req *c, char *url,
  +			  const char *proxyhost, int proxyport)
   {
       struct sockaddr_in server;
       struct in_addr destaddr;
       struct hostent server_hp;
       const char *host, *err;
       char *p;
  -    int   port, sock;
  +    int port, sock;
       char buffer[HUGE_STRING_LEN];
  -    int  nbytes, i, j;
  +    int nbytes, i, j;
       fd_set fds;
   
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)get_module_config(sconf, &proxy_module);
  -    struct noproxy_entry *npent=(struct noproxy_entry *)conf->noproxies->elts;
  +    (proxy_server_conf *) 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;
  - 
  +    server.sin_family = AF_INET;
  +
       /* Break the URL into host:port pairs */
   
       host = url;
       p = strchr(url, ':');
  -    if (p==NULL)
  +    if (p == NULL)
   	port = DEFAULT_HTTPS_PORT;
  -    else
  -    {
  -      port = atoi(p+1);
  -      *p='\0';
  +    else {
  +	port = atoi(p + 1);
  +	*p = '\0';
       }
  - 
  +
   /* check if ProxyBlock directive on this host */
       destaddr.s_addr = ap_inet_addr(host);
  -    for (i=0; i < conf->noproxies->nelts; i++)
  -    {
  -        if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
  -          || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
  -            return proxyerror(r, "Connect to remote machine blocked");
  +    for (i = 0; i < conf->noproxies->nelts; i++) {
  +	if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
  +	    || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
  +	    return proxyerror(r, "Connect to remote machine blocked");
       }
   
  -    switch (port)
  -    {
  +    switch (port) {
   	case DEFAULT_HTTPS_PORT:
  -	case DEFAULT_SNEWS_PORT:
  +	    case DEFAULT_SNEWS_PORT:
   	    break;
   	default:
   	    return HTTP_SERVICE_UNAVAILABLE;
  @@ -146,38 +142,38 @@
   
       if (proxyhost) {
   	Explain2("CONNECT to remote proxy %s on port %d", proxyhost, proxyport);
  -    } else {
  -    	Explain2("CONNECT to %s on port %d", host, port);
       }
  - 
  +    else {
  +	Explain2("CONNECT to %s on port %d", host, port);
  +    }
  +
       server.sin_port = (proxyport ? htons(proxyport) : htons(port));
       err = proxy_host2addr(proxyhost ? proxyhost : host, &server_hp);
   
       if (err != NULL)
  -	return proxyerror(r, err); /* give up */
  - 
  -    sock = psocket(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);  
  -    if (sock == -1)
  -    {     
  -        aplog_error(APLOG_MARK, APLOG_ERR, r->server,
  +	return proxyerror(r, err);	/* give up */
  +
  +    sock = psocket(r->pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  +    if (sock == -1) {
  +	aplog_error(APLOG_MARK, APLOG_ERR, r->server,
   		    "proxy: error creating socket");
  -        return SERVER_ERROR;
  -    }     
  - 
  +	return SERVER_ERROR;
  +    }
  +
       j = 0;
       while (server_hp.h_addr_list[j] != NULL) {
  -        memcpy(&server.sin_addr, server_hp.h_addr_list[j],
  -            sizeof(struct in_addr));
  -        i = proxy_doconnect(sock, &server, r);
  -        if (i == 0)
  -            break; 
  -        j++;
  -    }   
  +	memcpy(&server.sin_addr, server_hp.h_addr_list[j],
  +	       sizeof(struct in_addr));
  +	i = proxy_doconnect(sock, &server, r);
  +	if (i == 0)
  +	    break;
  +	j++;
  +    }
       if (i == -1) {
   	pclosesocket(r->pool, sock);
  -        return proxyerror(r, "Could not connect to remote machine");
  +	return proxyerror(r, "Could not connect to remote machine");
       }
  - 
  +
       /* If we are connecting through a remote proxy, we need to pass
        * the CONNECT request on to it.
        */
  @@ -187,67 +183,65 @@
   	 * a HTTP/1.0 request to keep things simple.
   	 */
   	Explain0("Sending the CONNECT request to the remote proxy");
  -	ap_snprintf(buffer, sizeof(buffer), "CONNECT %s HTTP/1.0\015\012", 
  -	    r->uri); 
  +	ap_snprintf(buffer, sizeof(buffer), "CONNECT %s HTTP/1.0\015\012",
  +		    r->uri);
   	write(sock, buffer, strlen(buffer));
   	ap_snprintf(buffer, sizeof(buffer),
  -	    "Proxy-agent: %s\015\012\015\012", SERVER_VERSION);
  +		    "Proxy-agent: %s\015\012\015\012", SERVER_VERSION);
   	write(sock, buffer, strlen(buffer));
  -    } else {
  +    }
  +    else {
   	Explain0("Returning 200 OK Status");
   	rvputs(r, "HTTP/1.0 200 Connection established\015\012", NULL);
   	rvputs(r, "Proxy-agent: ", SERVER_VERSION, "\015\012\015\012", NULL);
   	bflush(r->connection->client);
       }
   
  -    while (1) /* Infinite loop until error (one side closes the connection) */
  -    {
  -      FD_ZERO(&fds);
  -      FD_SET(sock, &fds);
  -      FD_SET(r->connection->client->fd, &fds);
  -    
  -      Explain0("Going to sleep (select)");
  -      i = ap_select((r->connection->client->fd > sock ?
  -	r->connection->client->fd+1 :
  -	sock+1), &fds, NULL, NULL, NULL);
  -      Explain1("Woke from select(), i=%d",i);
  -    
  -      if (i)
  -      {
  -        if (FD_ISSET(sock, &fds))
  -        {
  -           Explain0("sock was set");
  -           if((nbytes=read(sock,buffer,HUGE_STRING_LEN))!=0)
  -           {
  -              if (nbytes==-1)
  -		  break;
  -              if (write(r->connection->client->fd, buffer, nbytes)==EOF)
  -		  break;
  -              Explain1("Wrote %d bytes to client", nbytes);
  -           }
  -           else break;
  -        }
  -        else if (FD_ISSET(r->connection->client->fd, &fds))
  -        { 
  -           Explain0("client->fd was set");
  -           if((nbytes=read(r->connection->client->fd,buffer,
  -		HUGE_STRING_LEN))!=0)   
  -           {
  -              if (nbytes==-1)
  -		  break;
  -              if (write(sock,buffer,nbytes)==EOF)
  -		  break;
  -              Explain1("Wrote %d bytes to server", nbytes);
  -           }
  -           else break;
  -        }
  -        else break; /* Must be done waiting */
  -      }
  -      else break;
  +    while (1) {			/* Infinite loop until error (one side closes the connection) */
  +	FD_ZERO(&fds);
  +	FD_SET(sock, &fds);
  +	FD_SET(r->connection->client->fd, &fds);
  +
  +	Explain0("Going to sleep (select)");
  +	i = ap_select((r->connection->client->fd > sock ?
  +		       r->connection->client->fd + 1 :
  +		       sock + 1), &fds, NULL, NULL, NULL);
  +	Explain1("Woke from select(), i=%d", i);
  +
  +	if (i) {
  +	    if (FD_ISSET(sock, &fds)) {
  +		Explain0("sock was set");
  +		if ((nbytes = read(sock, buffer, HUGE_STRING_LEN)) != 0) {
  +		    if (nbytes == -1)
  +			break;
  +		    if (write(r->connection->client->fd, buffer, nbytes) == EOF)
  +			break;
  +		    Explain1("Wrote %d bytes to client", nbytes);
  +		}
  +		else
  +		    break;
  +	    }
  +	    else if (FD_ISSET(r->connection->client->fd, &fds)) {
  +		Explain0("client->fd was set");
  +		if ((nbytes = read(r->connection->client->fd, buffer,
  +				   HUGE_STRING_LEN)) != 0) {
  +		    if (nbytes == -1)
  +			break;
  +		    if (write(sock, buffer, nbytes) == EOF)
  +			break;
  +		    Explain1("Wrote %d bytes to server", nbytes);
  +		}
  +		else
  +		    break;
  +	    }
  +	    else
  +		break;		/* Must be done waiting */
  +	}
  +	else
  +	    break;
       }
   
  -    pclosesocket(r->pool,sock);
  -    
  -    return OK;
  -}     
  +    pclosesocket(r->pool, sock);
   
  +    return OK;
  +}
  
  
  
  1.38      +415 -424  apachen/src/modules/proxy/proxy_ftp.c
  
  Index: proxy_ftp.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_ftp.c,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- proxy_ftp.c	1997/09/06 14:16:57	1.37
  +++ proxy_ftp.c	1997/09/16 00:59:40	1.38
  @@ -61,19 +61,17 @@
   /*
    * Decodes a '%' escaped string, and returns the number of characters
    */
  -static int
  -decodeenc(char *x)
  +static int decodeenc(char *x)
   {
       int i, j, ch;
   
  -    if (x[0] == '\0') return 0; /* special case for no characters */
  -    for (i=0, j=0; x[i] != '\0'; i++, j++)
  -    {
  +    if (x[0] == '\0')
  +	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];
  -	if ( ch == '%' && isxdigit(x[i+1]) && isxdigit(x[i+2]))
  -	{
  -	    ch = proxy_hex2c(&x[i+1]);
  +	if (ch == '%' && isxdigit(x[i + 1]) && isxdigit(x[i + 2])) {
  +	    ch = proxy_hex2c(&x[i + 1]);
   	    i += 2;
   	}
   	x[j] = ch;
  @@ -86,20 +84,18 @@
    * checks an encoded ftp string for bad characters, namely, CR, LF or
    * non-ascii character
    */
  -static int
  -ftp_check_string(const char *x)
  +static int ftp_check_string(const char *x)
   {
       int i, ch;
   
  -    for (i=0; x[i] != '\0'; i++)
  -    {
  +    for (i = 0; x[i] != '\0'; i++) {
   	ch = x[i];
  -	if ( ch == '%' && isxdigit(x[i+1]) && isxdigit(x[i+2]))
  -	{
  -	    ch = proxy_hex2c(&x[i+1]);
  +	if (ch == '%' && isxdigit(x[i + 1]) && isxdigit(x[i + 2])) {
  +	    ch = proxy_hex2c(&x[i + 1]);
   	    i += 2;
   	}
  -	if (ch == '\015' || ch == '\012' || (ch & 0x80)) return 0;
  +	if (ch == '\015' || ch == '\012' || (ch & 0x80))
  +	    return 0;
       }
       return 1;
   }
  @@ -107,19 +103,21 @@
   /*
    * Canonicalise ftp URLs.
    */
  -int
  -proxy_ftp_canon(request_rec *r, char *url)
  +int proxy_ftp_canon(request_rec *r, char *url)
   {
       char *user, *password, *host, *path, *parms, *p, sport[7];
  -    pool *pool=r->pool;
  +    pool *pool = r->pool;
       const char *err;
       int port;
   
       port = DEFAULT_FTP_PORT;
       err = proxy_canon_netloc(pool, &url, &user, &password, &host, &port);
  -    if (err) return BAD_REQUEST;
  -    if (user != NULL && !ftp_check_string(user)) return BAD_REQUEST;
  -    if (password != NULL && !ftp_check_string(password)) return BAD_REQUEST;
  +    if (err)
  +	return BAD_REQUEST;
  +    if (user != NULL && !ftp_check_string(user))
  +	return BAD_REQUEST;
  +    if (password != NULL && !ftp_check_string(password))
  +	return BAD_REQUEST;
   
   /* now parse path/parameters args, according to rfc1738 */
   /* N.B. if this isn't a true proxy request, then the URL path
  @@ -128,30 +126,32 @@
    * path.
    */
       p = strchr(url, ';');
  -    if (p != NULL)
  -    {
  +    if (p != NULL) {
   	*(p++) = '\0';
   	parms = proxy_canonenc(pool, p, strlen(p), enc_parm, r->proxyreq);
  -	if (parms == NULL) return BAD_REQUEST;
  -    } else
  +	if (parms == NULL)
  +	    return BAD_REQUEST;
  +    }
  +    else
   	parms = "";
   
       path = proxy_canonenc(pool, url, strlen(url), enc_path, r->proxyreq);
  -    if (path == NULL) return BAD_REQUEST;
  -    if (!ftp_check_string(path)) return BAD_REQUEST;
  +    if (path == NULL)
  +	return BAD_REQUEST;
  +    if (!ftp_check_string(path))
  +	return BAD_REQUEST;
   
  -    if (!r->proxyreq && r->args != NULL)
  -    {
  -	if (p != NULL)
  -	{
  +    if (!r->proxyreq && r->args != NULL) {
  +	if (p != NULL) {
   	    p = proxy_canonenc(pool, r->args, strlen(r->args), enc_parm, 1);
  -	    if (p == NULL) return BAD_REQUEST;
  +	    if (p == NULL)
  +		return BAD_REQUEST;
   	    parms = pstrcat(pool, parms, "?", p, NULL);
   	}
  -	else
  -	{
  +	else {
   	    p = proxy_canonenc(pool, r->args, strlen(r->args), enc_fpath, 1);
  -	    if (p == NULL) return BAD_REQUEST;
  +	    if (p == NULL)
  +		return BAD_REQUEST;
   	    path = pstrcat(pool, path, "?", p, NULL);
   	}
   	r->args = NULL;
  @@ -159,14 +159,16 @@
   
   /* now, rebuild URL */
   
  -    if (port != DEFAULT_FTP_PORT) ap_snprintf(sport, sizeof(sport), ":%d", port);
  -    else sport[0] = '\0';
  +    if (port != DEFAULT_FTP_PORT)
  +	ap_snprintf(sport, sizeof(sport), ":%d", port);
  +    else
  +	sport[0] = '\0';
   
       r->filename = pstrcat(pool, "proxy:ftp://", (user != NULL) ? user : "",
  -			  (password != NULL) ? ":" : "",
  -			  (password != NULL) ? password : "",
  -			  (user != NULL) ? "@" : "", host, sport, "/", path,
  -			  (parms[0] != '\0') ? ";" : "", parms, NULL);
  +			       (password != NULL) ? ":" : "",
  +			       (password != NULL) ? password : "",
  +		          (user != NULL) ? "@" : "", host, sport, "/", path,
  +			       (parms[0] != '\0') ? ";" : "", parms, NULL);
   
       return OK;
   }
  @@ -175,14 +177,14 @@
    * Returns the ftp status code;
    *  or -1 on I/O error, 0 on data error
    */
  -static int
  -ftp_getrc(BUFF *f)
  +static int ftp_getrc(BUFF *f)
   {
       int i, len, status;
       char linebuff[100], buff[5];
   
       len = bgets(linebuff, 100, f);
  -    if (len == -1) return -1;
  +    if (len == -1)
  +	return -1;
   /* check format */
       if (len < 5 || !isdigit(linebuff[0]) || !isdigit(linebuff[1]) ||
   	!isdigit(linebuff[2]) || (linebuff[3] != ' ' && linebuff[3] != '-'))
  @@ -190,22 +192,19 @@
       else
   	status = 100 * linebuff[0] + 10 * linebuff[1] + linebuff[2] - 111 * '0';
   
  -    if (linebuff[len-1] != '\n')
  -    {
  +    if (linebuff[len - 1] != '\n') {
   	i = bskiplf(f);
       }
   
  -/* skip continuation lines */    
  -    if (linebuff[3] == '-')
  -    {
  +/* skip continuation lines */
  +    if (linebuff[3] == '-') {
   	memcpy(buff, linebuff, 3);
   	buff[3] = ' ';
  -	do
  -	{
  +	do {
   	    len = bgets(linebuff, 100, f);
  -	    if (len == -1) return -1;
  -	    if (linebuff[len-1] != '\n')
  -	    {
  +	    if (len == -1)
  +		return -1;
  +	    if (linebuff[len - 1] != '\n') {
   		i = bskiplf(f);
   	    }
   	} while (memcmp(linebuff, buff, 4) != 0);
  @@ -215,15 +214,15 @@
   }
   
   static char *
  -encode_space(request_rec *r, char *path)
  +     encode_space(request_rec *r, char *path)
   {
  -    pool *pool=r->pool;
  +    pool *pool = r->pool;
       char *newpath;
       int i, j, len;
   
       len = strlen(path);
       newpath = palloc(pool, 3 * len + 1);
  -    for (i=0, j=0; i < len; i++, j++) {
  +    for (i = 0, j = 0; i < len; i++, j++) {
   	if (path[i] != ' ')
   	    newpath[j] = path[i];
   	else {
  @@ -235,8 +234,7 @@
       return newpath;
   }
   
  -static long int
  -send_dir(BUFF *f, request_rec *r, BUFF *f2, struct cache_req *c, char *url)
  +static long int send_dir(BUFF *f, request_rec *r, BUFF *f2, struct cache_req *c, char *url)
   {
       char buf[IOBUFSIZE];
       char buf2[IOBUFSIZE];
  @@ -252,8 +250,7 @@
       conn_rec *con = r->connection;
   
       tempurl = pstrdup(r->pool, url);
  -    if ((n = strcspn(tempurl, "@")) != strlen(tempurl))	/* hide user/passwd */
  -    {
  +    if ((n = strcspn(tempurl, "@")) != strlen(tempurl)) {	/* hide user/passwd */
   	memmove(tempurl + (n - 5), tempurl, 6);
   	tempurl += n - 5;	/* leave room for ftp:// */
       }
  @@ -261,124 +258,131 @@
       n = decodeenc(tempurl);
       ap_snprintf(buf, sizeof(buf), "<HTML><HEAD><TITLE>%s</TITLE></HEAD><BODY><H1>Directory %s</H1><HR><PRE>", tempurl, tempurl);
       bwrite(con->client, buf, strlen(buf));
  -    if (f2 != NULL) bwrite(f2, buf, strlen(buf));
  -    total_bytes_sent=strlen(buf);
  -    while(!con->aborted)
  -    {
  -        n = bgets(buf, IOBUFSIZE, f);
  -        if (n == -1) /* input error */
  -        {
  -            if (f2 != NULL) f2 = proxy_cache_error(c);
  -            break;
  -        }
  -        if (n == 0) break; /* EOF */
  -        if(buf[0]=='l')
  -        {
  -            char *link;
  -
  -            link=strstr(buf, " -> ");
  -            filename=link;
  -            do filename--; while (filename[0]!=' ');
  -            *(filename++)=0;
  -            *(link++)=0;
  -            ap_snprintf(urlptr, sizeof(urlptr), "%s%s%s",url,(url[strlen(url)-1]=='/' ? "" : "/"), filename);
  -            ap_snprintf(buf2, sizeof(urlptr), "%s <A HREF=\"%s\">%s %s</A>\015\012", buf, urlptr, filename, link);
  -            strncpy(buf, buf2, sizeof(buf)-1);
  -	    buf[sizeof(buf)-1] = '\0';
  -            n=strlen(buf);
  -        }
  -        else if(buf[0]=='d' || buf[0]=='-' || buf[0]=='l' || isdigit(buf[0]))
  -        {
  -	    if(isdigit(buf[0])) {		/* handle DOS dir */
  -	        searchptr = strchr(buf, '<');
  -	        if(searchptr != NULL)
  +    if (f2 != NULL)
  +	bwrite(f2, buf, strlen(buf));
  +    total_bytes_sent = strlen(buf);
  +    while (!con->aborted) {
  +	n = bgets(buf, IOBUFSIZE, f);
  +	if (n == -1) {		/* input error */
  +	    if (f2 != NULL)
  +		f2 = proxy_cache_error(c);
  +	    break;
  +	}
  +	if (n == 0)
  +	    break;		/* EOF */
  +	if (buf[0] == 'l') {
  +	    char *link;
  +
  +	    link = strstr(buf, " -> ");
  +	    filename = link;
  +	    do
  +		filename--;
  +	    while (filename[0] != ' ');
  +	    *(filename++) = 0;
  +	    *(link++) = 0;
  +	    ap_snprintf(urlptr, sizeof(urlptr), "%s%s%s", url, (url[strlen(url) - 1] == '/' ? "" : "/"), filename);
  +	    ap_snprintf(buf2, sizeof(urlptr), "%s <A HREF=\"%s\">%s %s</A>\015\012", buf, urlptr, filename, link);
  +	    strncpy(buf, buf2, sizeof(buf) - 1);
  +	    buf[sizeof(buf) - 1] = '\0';
  +	    n = strlen(buf);
  +	}
  +	else if (buf[0] == 'd' || buf[0] == '-' || buf[0] == 'l' || isdigit(buf[0])) {
  +	    if (isdigit(buf[0])) {	/* handle DOS dir */
  +		searchptr = strchr(buf, '<');
  +		if (searchptr != NULL)
   		    *searchptr = '[';
  -	        searchptr = strchr(buf, '>');
  -	        if(searchptr != NULL)
  +		searchptr = strchr(buf, '>');
  +		if (searchptr != NULL)
   		    *searchptr = ']';
   	    }
  -		
  -            filename=strrchr(buf, ' ');
  -            *(filename++)=0;
  -            filename[strlen(filename)-1]=0;
   
  -            /* handle filenames with spaces in 'em */
  -            if(!strcmp(filename, ".") || !strcmp(filename, "..") || firstfile) {
  +	    filename = strrchr(buf, ' ');
  +	    *(filename++) = 0;
  +	    filename[strlen(filename) - 1] = 0;
  +
  +	    /* handle filenames with spaces in 'em */
  +	    if (!strcmp(filename, ".") || !strcmp(filename, "..") || firstfile) {
   		firstfile = 0;
  -                searchidx = filename - buf;
  -            }
  -            else if (searchidx != 0 && buf[searchidx] != 0) {
  -                *(--filename) = ' ';
  -                buf[searchidx - 1] = 0;
  -                filename = &buf[searchidx];    
  -            }   
  -
  -            /* Special handling for '.' and '..' */
  -            if (!strcmp(filename, "."))
  -            {
  -                ap_snprintf(urlptr, sizeof(urlptr), "%s",url);
  -                ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, urlptr, filename);
  -            }
  -            else if (!strcmp(filename, ".."))
  -            {
  -                char temp[200];
  -                char newpath[200];
  -                char *method, *host, *path, *newfile;
  -   
  -                strncpy(temp, url, sizeof(temp)-1);
  -		temp[sizeof(temp)-1] = '\0';
  -                method=temp;
  -
  -                host=strchr(method,':');
  -                if (host == NULL) host="";
  -                else *(host++)=0;
  -                host++; host++;
  -                
  -                path=strchr(host,'/');
  -                if (path == NULL) path="";
  -                else *(path++)=0;
  -                
  -                strncpy(newpath, path, sizeof(newpath)-1);
  -		newpath[sizeof(newpath)-1] = '\0';
  -                newfile=strrchr(newpath,'/');
  -                if (newfile) *(newfile)=0;
  -                else newpath[0]=0;
  -
  -                ap_snprintf(urlptr, sizeof(urlptr), "%s://%s/%s",method,host,newpath);
  -                ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, urlptr, filename);
  -            }
  -            else 
  -            {
  -                ap_snprintf(urlptr, sizeof(urlptr), "%s%s%s",url,(url[strlen(url)-1]=='/' ? "" : "/"), filename);
  +		searchidx = filename - buf;
  +	    }
  +	    else if (searchidx != 0 && buf[searchidx] != 0) {
  +		*(--filename) = ' ';
  +		buf[searchidx - 1] = 0;
  +		filename = &buf[searchidx];
  +	    }
  +
  +	    /* Special handling for '.' and '..' */
  +	    if (!strcmp(filename, ".")) {
  +		ap_snprintf(urlptr, sizeof(urlptr), "%s", url);
  +		ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, urlptr, filename);
  +	    }
  +	    else if (!strcmp(filename, "..")) {
  +		char temp[200];
  +		char newpath[200];
  +		char *method, *host, *path, *newfile;
  +
  +		strncpy(temp, url, sizeof(temp) - 1);
  +		temp[sizeof(temp) - 1] = '\0';
  +		method = temp;
  +
  +		host = strchr(method, ':');
  +		if (host == NULL)
  +		    host = "";
  +		else
  +		    *(host++) = 0;
  +		host++;
  +		host++;
  +
  +		path = strchr(host, '/');
  +		if (path == NULL)
  +		    path = "";
  +		else
  +		    *(path++) = 0;
  +
  +		strncpy(newpath, path, sizeof(newpath) - 1);
  +		newpath[sizeof(newpath) - 1] = '\0';
  +		newfile = strrchr(newpath, '/');
  +		if (newfile)
  +		    *(newfile) = 0;
  +		else
  +		    newpath[0] = 0;
  +
  +		ap_snprintf(urlptr, sizeof(urlptr), "%s://%s/%s", method, host, newpath);
  +		ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, urlptr, filename);
  +	    }
  +	    else {
  +		ap_snprintf(urlptr, sizeof(urlptr), "%s%s%s", url, (url[strlen(url) - 1] == '/' ? "" : "/"), filename);
   		newurlptr = encode_space(r, urlptr);
  -                ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, newurlptr, filename);
  -            }
  -            strncpy(buf, buf2, sizeof(buf));
  -	    buf[sizeof(buf)-1] = '\0';
  -            n=strlen(buf);
  -        }      
  +		ap_snprintf(buf2, sizeof(buf2), "%s <A HREF=\"%s\">%s</A>\015\012", buf, newurlptr, filename);
  +	    }
  +	    strncpy(buf, buf2, sizeof(buf));
  +	    buf[sizeof(buf) - 1] = '\0';
  +	    n = strlen(buf);
  +	}
   
  -        o=0;
  +	o = 0;
   	total_bytes_sent += n;
   
   	if (f2 != NULL)
  -	    if (bwrite(f2, buf, n) != n) f2 = proxy_cache_error(c);
  -	
  -        while(n && !r->connection->aborted) {
  -            w = bwrite(con->client, &buf[o], n);
  +	    if (bwrite(f2, buf, n) != n)
  +		f2 = proxy_cache_error(c);
  +
  +	while (n && !r->connection->aborted) {
  +	    w = bwrite(con->client, &buf[o], n);
   	    if (w <= 0)
   		break;
  -	    reset_timeout(r); /* reset timeout after successfule write */
  -            n-=w;
  -            o+=w;
  -        }
  +	    reset_timeout(r);	/* reset timeout after successfule write */
  +	    n -= w;
  +	    o += w;
  +	}
       }
       ap_snprintf(buf, sizeof(buf), "</PRE><HR><I><A HREF=\"http://www.apache.org\">%s</A></I></BODY></HTML>", SERVER_VERSION);
       bwrite(con->client, buf, strlen(buf));
  -    if (f2 != NULL) bwrite(f2, buf, strlen(buf));
  -    total_bytes_sent+=strlen(buf);
  +    if (f2 != NULL)
  +	bwrite(f2, buf, strlen(buf));
  +    total_bytes_sent += strlen(buf);
       bflush(con->client);
  -    
  +
       return total_bytes_sent;
   }
   
  @@ -388,8 +392,7 @@
    * Troy Morrison <spiffnet@zoom.com>
    * PASV added by Chuck
    */
  -int
  -proxy_ftp_handler(request_rec *r, struct cache_req *c, char *url)
  +int proxy_ftp_handler(request_rec *r, struct cache_req *c, char *url)
   {
       char *host, *path, *p, *user, *password, *parms;
       const char *err;
  @@ -403,16 +406,16 @@
       array_header *resp_hdrs;
       BUFF *f, *cache;
       BUFF *data = NULL;
  -    pool *pool=r->pool;
  -    int one=1;
  -    const long int zero=0L;
  +    pool *pool = r->pool;
  +    int one = 1;
  +    const long int zero = 0L;
       NET_SIZE_T clen;
   
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)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;
  +    (proxy_server_conf *) 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;
   
   /* stuff for PASV mode */
       unsigned int presult, h0, h1, h2, h3, p0, p1;
  @@ -422,10 +425,11 @@
       int pasvmode = 0;
       char pasv[64];
       char *pstr;
  - 
  +
   /* we only support GET and HEAD */
   
  -    if (r->method_number != M_GET) return NOT_IMPLEMENTED;
  +    if (r->method_number != M_GET)
  +	return NOT_IMPLEMENTED;
   
   /* We break the URL into host, port, path-search */
   
  @@ -440,23 +444,21 @@
       user = password = NULL;
       nocache = 0;
       p = strchr(host, '@');
  -    if (p != NULL)
  -    {
  +    if (p != NULL) {
   	(*p++) = '\0';
   	user = host;
   	host = p;
   /* find password */
   	p = strchr(user, ':');
  -	if (p != NULL)
  -	{
  +	if (p != NULL) {
   	    *(p++) = '\0';
   	    password = p;
   	    passlen = decodeenc(password);
   	}
   	userlen = decodeenc(user);
  -	nocache = 1; /* don't cache when a username is supplied */
  -    } else
  -    {
  +	nocache = 1;		/* don't cache when a username is supplied */
  +    }
  +    else {
   	user = "anonymous";
   	userlen = 9;
   
  @@ -465,8 +467,7 @@
       }
   
       p = strchr(host, ':');
  -    if (p != NULL)
  -    {
  +    if (p != NULL) {
   	*(p++) = '\0';
   	if (isdigit(*p))
   	    port = atoi(p);
  @@ -474,55 +475,55 @@
   
   /* check if ProxyBlock directive on this host */
       destaddr.s_addr = ap_inet_addr(host);
  -    for (i=0; i < conf->noproxies->nelts; i++)
  -    {
  -        if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
  -          || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
  -            return proxyerror(r, "Connect to remote machine blocked");
  +    for (i = 0; i < conf->noproxies->nelts; i++) {
  +	if ((npent[i].name != NULL && strstr(host, npent[i].name) != NULL)
  +	    || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
  +	    return proxyerror(r, "Connect to remote machine blocked");
       }
   
  -    Explain2("FTP: connect to %s:%d",host,port);
  +    Explain2("FTP: connect to %s:%d", host, port);
   
       parms = strchr(path, ';');
  -    if (parms != NULL) *(parms++) = '\0';
  +    if (parms != NULL)
  +	*(parms++) = '\0';
   
       memset(&server, 0, sizeof(struct sockaddr_in));
       server.sin_family = AF_INET;
       server.sin_port = htons(port);
       err = proxy_host2addr(host, &server_hp);
  -    if (err != NULL) return proxyerror(r, err); /* give up */
  +    if (err != NULL)
  +	return proxyerror(r, err);	/* give up */
   
       sock = psocket(pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  -    if (sock == -1)
  -    {
  +    if (sock == -1) {
   	proxy_log_uerror("socket", NULL, "proxy: error creating socket",
  -	    r->server);
  +			 r->server);
   	return SERVER_ERROR;
       }
   
       if (conf->recv_buffer_size) {
  -      if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
  -		     (const char *) &conf->recv_buffer_size, sizeof(int))
  -	  == -1) {
  -	proxy_log_uerror("setsockopt", "(SO_RCVBUF)",
  -			 "Failed to set RecvBufferSize, using default",
  -			 r->server);
  -      }
  +	if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
  +		       (const char *) &conf->recv_buffer_size, sizeof(int))
  +	    == -1) {
  +	    proxy_log_uerror("setsockopt", "(SO_RCVBUF)",
  +			     "Failed to set RecvBufferSize, using default",
  +			     r->server);
  +	}
       }
   
  -    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
  -		   sizeof(one)) == -1)
  -    {
  +    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &one,
  +		   sizeof(one)) == -1) {
   	proxy_log_uerror("setsockopt", NULL,
  -	    "proxy: error setting reuseaddr option", r->server);
  +			 "proxy: error setting reuseaddr option", r->server);
   	pclosesocket(pool, sock);
   	return SERVER_ERROR;
       }
   
   #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) {
  +	for (; ip_addr->s_addr != 0; ++ip_addr) {
   	    memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
   	    i = proxy_doconnect(sock, &server, r);
   	    if (i == 0)
  @@ -532,16 +533,16 @@
   #else
       j = 0;
       while (server_hp.h_addr_list[j] != NULL) {
  -        memcpy(&server.sin_addr, server_hp.h_addr_list[j],
  -            sizeof(struct in_addr));
  -        i = proxy_doconnect(sock, &server, r);
  -        if (i == 0)
  -            break; 
  -        j++;
  -    }   
  +	memcpy(&server.sin_addr, server_hp.h_addr_list[j],
  +	       sizeof(struct in_addr));
  +	i = proxy_doconnect(sock, &server, r);
  +	if (i == 0)
  +	    break;
  +	j++;
  +    }
   #endif
       if (i == -1) {
  -	pclosesocket (pool, sock);
  +	pclosesocket(pool, sock);
   	return proxyerror(r, "Could not connect to remote machine");
       }
   
  @@ -550,7 +551,7 @@
   /* shouldn't we implement telnet control options here? */
   
   /* possible results: 120, 220, 421 */
  -    hard_timeout ("proxy ftp", r);
  +    hard_timeout("proxy ftp", r);
       i = ftp_getrc(f);
       Explain1("FTP: returned status %d", i);
       if (i == -1) {
  @@ -567,13 +568,13 @@
       bputs("USER ", f);
       bwrite(f, user, userlen);
       bputs("\015\012", f);
  -    bflush(f); /* capture any errors */
  -    Explain1("FTP: USER %s",user);
  -    
  +    bflush(f);			/* capture any errors */
  +    Explain1("FTP: USER %s", user);
  +
   /* possible results; 230, 331, 332, 421, 500, 501, 530 */
   /* states: 1 - error, 2 - success; 3 - send password, 4,5 fail */
       i = ftp_getrc(f);
  -    Explain1("FTP: returned status %d",i);
  +    Explain1("FTP: returned status %d", i);
       if (i == -1) {
   	kill_timeout(r);
   	return proxyerror(r, "Error sending to remote server");
  @@ -586,18 +587,18 @@
   	kill_timeout(r);
   	return BAD_GATEWAY;
       }
  -	
  -    if (i == 331) /* send password */
  -    {
  -	if (password == NULL) return FORBIDDEN;
  +
  +    if (i == 331) {		/* send password */
  +	if (password == NULL)
  +	    return FORBIDDEN;
   	bputs("PASS ", f);
   	bwrite(f, password, passlen);
   	bputs("\015\012", f);
   	bflush(f);
  -        Explain1("FTP: PASS %s",password);
  +	Explain1("FTP: PASS %s", password);
   /* possible results 202, 230, 332, 421, 500, 501, 503, 530 */
   	i = ftp_getrc(f);
  -        Explain1("FTP: returned status %d",i);
  +	Explain1("FTP: returned status %d", i);
   	if (i == -1) {
   	    kill_timeout(r);
   	    return proxyerror(r, "Error sending to remote server");
  @@ -614,28 +615,28 @@
   	    kill_timeout(r);
   	    return BAD_GATEWAY;
   	}
  -    }  
  +    }
   
   /* set the directory */
   /* this is what we must do if we don't know the OS type of the remote
    * machine
    */
  -    for (;;)
  -    {
  +    for (;;) {
   	p = strchr(path, '/');
  -	if (p == NULL) break;
  +	if (p == NULL)
  +	    break;
   	*p = '\0';
   
   	len = decodeenc(path);
   	bputs("CWD ", f);
   	bwrite(f, path, len);
   	bputs("\015\012", f);
  -        bflush(f);
  -        Explain1("FTP: CWD %s",path);
  +	bflush(f);
  +	Explain1("FTP: CWD %s", path);
   /* responses: 250, 421, 500, 501, 502, 530, 550 */
   /* 1,3 error, 2 success, 4,5 failure */
   	i = ftp_getrc(f);
  -        Explain1("FTP: returned status %d",i);
  +	Explain1("FTP: returned status %d", i);
   	if (i == -1) {
   	    kill_timeout(r);
   	    return proxyerror(r, "Error sending to remote server");
  @@ -652,27 +653,27 @@
   	path = p + 1;
       }
   
  -    if (parms != NULL && strncmp(parms, "type=", 5) == 0)
  -    {
  +    if (parms != NULL && strncmp(parms, "type=", 5) == 0) {
   	parms += 5;
   	if ((parms[0] != 'd' && parms[0] != 'a' && parms[0] != 'i') ||
  -	    parms[1] != '\0') parms = "";
  +	    parms[1] != '\0')
  +	    parms = "";
       }
  -    else parms = "";
  +    else
  +	parms = "";
   
       /* changed to make binary transfers the default */
   
  -    if (parms[0] != 'a')
  -    {
  +    if (parms[0] != 'a') {
   	/* set type to image */
  -        /* TM - Added \015\012 to the end of TYPE I, otherwise it hangs the
  -           connection */
  +	/* TM - Added \015\012 to the end of TYPE I, otherwise it hangs the
  +	   connection */
   	bputs("TYPE I\015\012", f);
   	bflush(f);
  -        Explain0("FTP: TYPE I");
  +	Explain0("FTP: TYPE I");
   /* responses: 200, 421, 500, 501, 504, 530 */
   	i = ftp_getrc(f);
  -        Explain1("FTP: returned status %d",i);
  +	Explain1("FTP: returned status %d", i);
   	if (i == -1) {
   	    kill_timeout(r);
   	    return proxyerror(r, "Error sending to remote server");
  @@ -688,20 +689,19 @@
   
   /* try to set up PASV data connection first */
       dsock = psocket(pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  -    if (dsock == -1)
  -    { 
  +    if (dsock == -1) {
   	proxy_log_uerror("socket", NULL, "proxy: error creating PASV socket",
  -	    r->server);
  +			 r->server);
   	bclose(f);
   	kill_timeout(r);
  -        return SERVER_ERROR;
  +	return SERVER_ERROR;
       }
   
       if (conf->recv_buffer_size) {
  -    	if (setsockopt(dsock, SOL_SOCKET, SO_RCVBUF,
  -		(const char *)&conf->recv_buffer_size, sizeof(int)) == -1) {
  +	if (setsockopt(dsock, SOL_SOCKET, SO_RCVBUF,
  +	       (const char *) &conf->recv_buffer_size, sizeof(int)) == -1) {
   	    proxy_log_uerror("setsockopt", "(SO_RCVBUF)",
  -		"Failed to set RecvBufferSize, using default", r->server);
  +		  "Failed to set RecvBufferSize, using default", r->server);
   	}
       }
   
  @@ -709,22 +709,20 @@
       bflush(f);
       Explain0("FTP: PASV command issued");
   /* possible results: 227, 421, 500, 501, 502, 530 */
  -    i = bgets(pasv, sizeof(pasv), f); 
  +    i = bgets(pasv, sizeof(pasv), f);
   
  -    if (i == -1)
  -    {
  +    if (i == -1) {
   	proxy_log_uerror("command", NULL, "PASV: control connection is toast",
  -	    r->server);
  +			 r->server);
   	pclosesocket(pool, dsock);
   	bclose(f);
   	kill_timeout(r);
   	return SERVER_ERROR;
  -    } else
  -    {
  -	pasv[i-1] = '\0';
  +    }
  +    else {
  +	pasv[i - 1] = '\0';
   	pstr = strtok(pasv, " ");	/* separate result code */
  -	if (pstr != NULL)
  -	{
  +	if (pstr != NULL) {
   	    presult = atoi(pstr);
   	    pstr = strtok(NULL, "(");	/* separate address & port params */
   	    if (pstr != NULL)
  @@ -736,16 +734,15 @@
   	Explain1("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))
  -	{
  +		 "%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;
  +	    paddr = (((((h3 << 8) + h2) << 8) + h1) << 8) + h0;
  +	    pport = (p1 << 8) + p0;
   	    Explain5("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);
  +		     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);
   	    i = proxy_doconnect(dsock, &data_addr, r);
   
   	    if (i == -1) {
  @@ -753,58 +750,54 @@
   		return proxyerror(r, "Could not connect to remote machine");
   	    }
   	    else {
  -	        pasvmode = 1;
  +		pasvmode = 1;
   	    }
  -	} else
  +	}
  +	else
   	    pclosesocket(pool, dsock);	/* and try the regular way */
       }
   
  -    if (!pasvmode)	/* set up data connection */
  -    {
  -        clen = sizeof(struct sockaddr_in);
  -        if (getsockname(sock, (struct sockaddr *)&server, &clen) < 0)
  -        {
  +    if (!pasvmode) {		/* set up data connection */
  +	clen = sizeof(struct sockaddr_in);
  +	if (getsockname(sock, (struct sockaddr *) &server, &clen) < 0) {
   	    proxy_log_uerror("getsockname", NULL,
  -	        "proxy: error getting socket address", r->server);
  +			  "proxy: error getting socket address", r->server);
   	    bclose(f);
   	    kill_timeout(r);
   	    return SERVER_ERROR;
  -        }
  +	}
   
  -        dsock = psocket(pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  -        if (dsock == -1)
  -        {
  +	dsock = psocket(pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  +	if (dsock == -1) {
   	    proxy_log_uerror("socket", NULL, "proxy: error creating socket",
  -	        r->server);
  +			     r->server);
   	    bclose(f);
   	    kill_timeout(r);
   	    return SERVER_ERROR;
  -        }
  +	}
   
  -        if (setsockopt(dsock, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
  -		   sizeof(one)) == -1)
  -        {
  +	if (setsockopt(dsock, SOL_SOCKET, SO_REUSEADDR, (void *) &one,
  +		       sizeof(one)) == -1) {
   	    proxy_log_uerror("setsockopt", NULL,
  -	        "proxy: error setting reuseaddr option", r->server);
  +			"proxy: error setting reuseaddr option", r->server);
   	    pclosesocket(pool, dsock);
   	    bclose(f);
   	    kill_timeout(r);
   	    return SERVER_ERROR;
  -        }
  +	}
   
  -        if (bind(dsock, (struct sockaddr *)&server,
  -            sizeof(struct sockaddr_in)) == -1)
  -        {
  +	if (bind(dsock, (struct sockaddr *) &server,
  +		 sizeof(struct sockaddr_in)) == -1) {
   	    char buff[22];
   
   	    ap_snprintf(buff, sizeof(buff), "%s:%d", inet_ntoa(server.sin_addr), server.sin_port);
   	    proxy_log_uerror("bind", buff,
  -	        "proxy: error binding to ftp data socket", r->server);
  -    	    bclose(f);
  -    	    pclosesocket(pool, dsock);
  +		      "proxy: error binding to ftp data socket", r->server);
  +	    bclose(f);
  +	    pclosesocket(pool, dsock);
   	    return SERVER_ERROR;
  -        }
  -        listen(dsock, 2); /* only need a short queue */
  +	}
  +	listen(dsock, 2);	/* only need a short queue */
       }
   
   /* set request */
  @@ -812,58 +805,56 @@
   
       /* TM - if len == 0 then it must be a directory (you can't RETR nothing) */
   
  -    if(len==0)
  -    {
  -	parms="d";
  -    } else
  -    {
  -        bputs("SIZE ", f);
  -        bwrite(f, path, len);
  -        bputs("\015\012", f);
  -        bflush(f);
  -        Explain1("FTP: SIZE %s",path);
  -        i = ftp_getrc(f);
  -        Explain1("FTP: returned status %d", i);
  -        if (i != 500) /* Size command not recognized */
  -        {
  -            if (i==550) /* Not a regular file */
  -            {
  -                Explain0("FTP: SIZE shows this is a directory");
  -                parms="d";
  -                bputs("CWD ", f);
  -                bwrite(f, path, len);
  -                bputs("\015\012", f);
  -                bflush(f);
  -                Explain1("FTP: CWD %s",path);
  -                i = ftp_getrc(f);
  -                Explain1("FTP: returned status %d", i);
  -                if (i == -1) {
  +    if (len == 0) {
  +	parms = "d";
  +    }
  +    else {
  +	bputs("SIZE ", f);
  +	bwrite(f, path, len);
  +	bputs("\015\012", f);
  +	bflush(f);
  +	Explain1("FTP: SIZE %s", path);
  +	i = ftp_getrc(f);
  +	Explain1("FTP: returned status %d", i);
  +	if (i != 500) {		/* Size command not recognized */
  +	    if (i == 550) {	/* Not a regular file */
  +		Explain0("FTP: SIZE shows this is a directory");
  +		parms = "d";
  +		bputs("CWD ", f);
  +		bwrite(f, path, len);
  +		bputs("\015\012", f);
  +		bflush(f);
  +		Explain1("FTP: CWD %s", path);
  +		i = ftp_getrc(f);
  +		Explain1("FTP: returned status %d", i);
  +		if (i == -1) {
   		    kill_timeout(r);
   		    return proxyerror(r, "Error sending to remote server");
  -                }
  -                if (i == 550) {
  +		}
  +		if (i == 550) {
   		    kill_timeout(r);
   		    return NOT_FOUND;
  -                }
  -                if (i != 250) {
  +		}
  +		if (i != 250) {
   		    kill_timeout(r);
   		    return BAD_GATEWAY;
  -                }
  -                path=""; len=0;
  -            }
  -        }
  +		}
  +		path = "";
  +		len = 0;
  +	    }
  +	}
       }
  -            
  -    if (parms[0] == 'd')
  -    {
  -	if (len != 0) bputs("LIST ", f);
  -	else bputs("LIST -lag", f);
  -        Explain1("FTP: LIST %s",(len==0 ? "" : path));
  +
  +    if (parms[0] == 'd') {
  +	if (len != 0)
  +	    bputs("LIST ", f);
  +	else
  +	    bputs("LIST -lag", f);
  +	Explain1("FTP: LIST %s", (len == 0 ? "" : path));
       }
  -    else
  -    {
  -        bputs("RETR ", f);
  -        Explain1("FTP: RETR %s",path);
  +    else {
  +	bputs("RETR ", f);
  +	Explain1("FTP: RETR %s", path);
       }
       bwrite(f, path, len);
       bputs("\015\012", f);
  @@ -871,44 +862,45 @@
   /* RETR: 110, 125, 150, 226, 250, 421, 425, 426, 450, 451, 500, 501, 530, 550
      NLST: 125, 150, 226, 250, 421, 425, 426, 450, 451, 500, 501, 502, 530 */
       rc = ftp_getrc(f);
  -    Explain1("FTP: returned status %d",rc);
  +    Explain1("FTP: returned status %d", rc);
       if (rc == -1) {
   	kill_timeout(r);
   	return proxyerror(r, "Error sending to remote server");
       }
  -    if (rc == 550)
  -    {
  -       Explain0("FTP: RETR failed, trying LIST instead");
  -       parms="d";
  -       bputs("CWD ", f);
  -       bwrite(f, path, len);
  -       bputs("\015\012", f);
  -       bflush(f);
  -       Explain1("FTP: CWD %s", path);
  -       rc = ftp_getrc(f);
  -       Explain1("FTP: returned status %d", rc);
  -       if (rc == -1) {
  -          kill_timeout(r);
  -          return proxyerror(r, "Error sending to remote server");
  -       }
  -       if (rc == 550) {
  -          kill_timeout(r);
  -          return NOT_FOUND;
  -       }
  -       if (rc != 250) {
  -          kill_timeout(r);
  -          return BAD_GATEWAY;
  -       }
  -
  -       bputs("LIST -lag\015\012", f);
  -       bflush(f);
  -       Explain0("FTP: LIST -lag");
  -       rc = ftp_getrc(f);
  -       Explain1("FTP: returned status %d", rc);
  -       if (rc == -1) return proxyerror(r, "Error sending to remote server");
  -    }   
  +    if (rc == 550) {
  +	Explain0("FTP: RETR failed, trying LIST instead");
  +	parms = "d";
  +	bputs("CWD ", f);
  +	bwrite(f, path, len);
  +	bputs("\015\012", f);
  +	bflush(f);
  +	Explain1("FTP: CWD %s", path);
  +	rc = ftp_getrc(f);
  +	Explain1("FTP: returned status %d", rc);
  +	if (rc == -1) {
  +	    kill_timeout(r);
  +	    return proxyerror(r, "Error sending to remote server");
  +	}
  +	if (rc == 550) {
  +	    kill_timeout(r);
  +	    return NOT_FOUND;
  +	}
  +	if (rc != 250) {
  +	    kill_timeout(r);
  +	    return BAD_GATEWAY;
  +	}
  +
  +	bputs("LIST -lag\015\012", f);
  +	bflush(f);
  +	Explain0("FTP: LIST -lag");
  +	rc = ftp_getrc(f);
  +	Explain1("FTP: returned status %d", rc);
  +	if (rc == -1)
  +	    return proxyerror(r, "Error sending to remote server");
  +    }
       kill_timeout(r);
  -    if (rc != 125 && rc != 150 && rc != 226 && rc != 250) return BAD_GATEWAY;
  +    if (rc != 125 && rc != 150 && rc != 226 && rc != 250)
  +	return BAD_GATEWAY;
   
       r->status = 200;
       r->status_line = "200 OK";
  @@ -916,64 +908,60 @@
       resp_hdrs = make_array(pool, 2, sizeof(struct hdr_entry));
       if (parms[0] == 'd')
   	proxy_add_header(resp_hdrs, "Content-Type", "text/html", HDR_REP);
  -    else
  -    {
  -        mime_find_ct(r);
  -        if(r->content_type != NULL)
  -        {
  -            proxy_add_header(resp_hdrs, "Content-Type", r->content_type,
  -		HDR_REP);
  -            Explain1("FTP: Content-Type set to %s",r->content_type);
  -        } else
  -	{
  +    else {
  +	mime_find_ct(r);
  +	if (r->content_type != NULL) {
  +	    proxy_add_header(resp_hdrs, "Content-Type", r->content_type,
  +			     HDR_REP);
  +	    Explain1("FTP: Content-Type set to %s", r->content_type);
  +	}
  +	else {
   	    proxy_add_header(resp_hdrs, "Content-Type", "text/plain", HDR_REP);
   	}
       }
   
  -/* check if NoCache directive on this host */ 
  -    for (i=0; i < conf->nocaches->nelts; i++)
  -    {
  -        if ((ncent[i].name != NULL && strstr(host, ncent[i].name) != NULL)
  -          || destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
  -            nocache = 1;
  +/* check if NoCache directive on this host */
  +    for (i = 0; i < conf->nocaches->nelts; i++) {
  +	if ((ncent[i].name != NULL && strstr(host, ncent[i].name) != NULL)
  +	    || destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
  +	    nocache = 1;
       }
   
       i = proxy_cache_update(c, resp_hdrs, 0, nocache);
   
  -    if (i != DECLINED)
  -    {
  +    if (i != DECLINED) {
   	pclosesocket(pool, dsock);
   	bclose(f);
   	return i;
       }
       cache = c->fp;
   
  -    if (!pasvmode)	/* wait for connection */
  -    {
  -        hard_timeout ("proxy ftp data connect", r);
  -        clen = sizeof(struct sockaddr_in);
  -        do csd = accept(dsock, (struct sockaddr *)&server, &clen);
  -        while (csd == -1 && errno == EINTR);
  -        if (csd == -1)
  -        {
  +    if (!pasvmode) {		/* wait for connection */
  +	hard_timeout("proxy ftp data connect", r);
  +	clen = sizeof(struct sockaddr_in);
  +	do
  +	    csd = accept(dsock, (struct sockaddr *) &server, &clen);
  +	while (csd == -1 && errno == EINTR);
  +	if (csd == -1) {
   	    proxy_log_uerror("accept", NULL,
  -	        "proxy: failed to accept data connection", r->server);
  +		      "proxy: failed to accept data connection", r->server);
   	    pclosesocket(pool, dsock);
   	    bclose(f);
   	    kill_timeout(r);
   	    proxy_cache_error(c);
   	    return BAD_GATEWAY;
  -        }
  -        note_cleanups_for_socket(pool, csd);
  -        data = bcreate(pool, B_RDWR | B_SOCKET);
  -        bpushfd(data, csd, -1);
  +	}
  +	note_cleanups_for_socket(pool, csd);
  +	data = bcreate(pool, B_RDWR | B_SOCKET);
  +	bpushfd(data, csd, -1);
   	kill_timeout(r);
  -    } else {
  -	data = bcreate(pool, B_RDWR | B_SOCKET); 
  +    }
  +    else {
  +	data = bcreate(pool, B_RDWR | B_SOCKET);
   	bpushfd(data, dsock, dsock);
       }
   
  -    hard_timeout ("proxy receive", r);
  +    hard_timeout("proxy receive", r);
   /* send response */
   /* write status line */
       if (!r->assbackwards)
  @@ -985,11 +973,11 @@
   
   /* send headers */
       len = resp_hdrs->nelts;
  -    hdr = (struct hdr_entry *)resp_hdrs->elts;
  -    for (i=0; i < len; i++)
  -    {
  +    hdr = (struct hdr_entry *) resp_hdrs->elts;
  +    for (i = 0; i < len; i++) {
   	if (hdr[i].field == NULL || hdr[i].value == NULL ||
  -	    hdr[i].value[0] == '\0') continue;
  +	    hdr[i].value[0] == '\0')
  +	    continue;
   	if (!r->assbackwards)
   	    rvputs(r, hdr[i].field, ": ", hdr[i].value, "\015\012", NULL);
   	if (cache != NULL)
  @@ -998,32 +986,36 @@
   		cache = proxy_cache_error(c);
       }
   
  -    if (!r->assbackwards) rputs("\015\012", r);
  +    if (!r->assbackwards)
  +	rputs("\015\012", r);
       if (cache != NULL)
  -	if (bputs("\015\012", cache) == -1) cache = proxy_cache_error(c);
  +	if (bputs("\015\012", cache) == -1)
  +	    cache = proxy_cache_error(c);
   
       bsetopt(r->connection->client, BO_BYTECT, &zero);
       r->sent_bodyct = 1;
   /* send body */
  -    if (!r->header_only)
  -    {
  -	if (parms[0] != 'd') proxy_send_fb(data, r, cache, c);
  -        else send_dir(data, r, cache, c, url);
  +    if (!r->header_only) {
  +	if (parms[0] != 'd')
  +	    proxy_send_fb(data, r, cache, c);
  +	else
  +	    send_dir(data, r, cache, c, url);
   
  -	if (rc == 125 || rc == 150) rc = ftp_getrc(f);
  -	if (rc != 226 && rc != 250) proxy_cache_error(c);
  +	if (rc == 125 || rc == 150)
  +	    rc = ftp_getrc(f);
  +	if (rc != 226 && rc != 250)
  +	    proxy_cache_error(c);
       }
  -    else
  -    {
  +    else {
   /* abort the transfer */
   	bputs("ABOR\015\012", f);
   	bflush(f);
   	if (!pasvmode)
  -            bclose(data);
  -        Explain0("FTP: ABOR");
  +	    bclose(data);
  +	Explain0("FTP: ABOR");
   /* responses: 225, 226, 421, 500, 501, 502 */
   	i = ftp_getrc(f);
  -        Explain1("FTP: returned status %d",i);
  +	Explain1("FTP: returned status %d", i);
       }
   
       kill_timeout(r);
  @@ -1033,7 +1025,7 @@
       bputs("QUIT\015\012", f);
       bflush(f);
       Explain0("FTP: QUIT");
  -/* responses: 221, 500 */    
  +/* responses: 221, 500 */
   
       if (pasvmode)
   	bclose(data);
  @@ -1043,4 +1035,3 @@
   
       return OK;
   }
  -
  
  
  
  1.33      +127 -128  apachen/src/modules/proxy/proxy_http.c
  
  Index: proxy_http.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_http.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- proxy_http.c	1997/09/06 14:16:57	1.32
  +++ proxy_http.c	1997/09/16 00:59:40	1.33
  @@ -63,8 +63,7 @@
    *  url    is the URL starting with the first '/'
    *  def_port is the default port for this scheme.
    */
  -int
  -proxy_http_canon(request_rec *r, char *url, const char *scheme, int def_port)
  +int proxy_http_canon(request_rec *r, char *url, const char *scheme, int def_port)
   {
       char *host, *path, *search, *p, sport[7];
       const char *err;
  @@ -75,55 +74,63 @@
    */
       port = def_port;
       err = proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
  -    if (err) return BAD_REQUEST;
  +    if (err)
  +	return 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
    */
  -    if (r->proxyreq)
  -    {
  +    if (r->proxyreq) {
   	p = strchr(url, '?');
  -	if (p != NULL) *(p++) = '\0';
  -    } else
  +	if (p != NULL)
  +	    *(p++) = '\0';
  +    }
  +    else
   	p = r->args;
   
   /* process path */
       path = proxy_canonenc(r->pool, url, strlen(url), enc_path, r->proxyreq);
  -    if (path == NULL) return BAD_REQUEST;
  +    if (path == NULL)
  +	return BAD_REQUEST;
   
   /* process search */
  -    if (p != NULL)
  -    {
  +    if (p != NULL) {
   	search = p;
  -	if (search == NULL) return BAD_REQUEST;
  -    } else
  +	if (search == NULL)
  +	    return BAD_REQUEST;
  +    }
  +    else
   	search = NULL;
   
  -    if (port != def_port) ap_snprintf(sport, sizeof(sport), ":%d", port);
  -    else sport[0] = '\0';
  +    if (port != def_port)
  +	ap_snprintf(sport, sizeof(sport), ":%d", port);
  +    else
  +	sport[0] = '\0';
   
       r->filename = pstrcat(r->pool, "proxy:", scheme, "://", host, sport, "/",
  -	path, (search) ? "?" : "", (search) ? search : "", NULL);
  +		   path, (search) ? "?" : "", (search) ? search : "", NULL);
       return OK;
   }
   
   /* Clear all connection-based headers from the incoming headers table */
  -static void clear_connection (table *headers)
  +static void clear_connection(table *headers)
   {
       char *name;
       char *next = table_get(headers, "Connection");
   
  -    if (!next) return;
  +    if (!next)
  +	return;
   
       while (*next) {
  -        name = next;
  -        while (*next && !isspace(*next) && (*next != ',')) ++next;
  -        while (*next && (isspace(*next) || (*next == ','))) {
  -            *next = '\0';
  -            ++next;
  -        }
  -        table_unset(headers, name);
  +	name = next;
  +	while (*next && !isspace(*next) && (*next != ','))
  +	    ++next;
  +	while (*next && (isspace(*next) || (*next == ','))) {
  +	    *next = '\0';
  +	    ++next;
  +	}
  +	table_unset(headers, name);
       }
       table_unset(headers, "Connection");
   }
  @@ -137,9 +144,8 @@
    * we return DECLINED so that we can try another proxy. (Or the direct
    * route.)
    */
  -int
  -proxy_http_handler(request_rec *r, struct cache_req *c, char *url,
  -	     const char *proxyhost, int proxyport)
  +int proxy_http_handler(request_rec *r, struct cache_req *c, char *url,
  +		       const char *proxyhost, int proxyport)
   {
       char *p;
       const char *err, *desthost;
  @@ -152,17 +158,17 @@
       BUFF *f, *cache;
       struct hdr_entry *hdr;
       char buffer[HUGE_STRING_LEN];
  -    pool *pool=r->pool;
  -    const long int zero=0L;
  +    pool *pool = r->pool;
  +    const long int zero = 0L;
       int destport = 0;
       char *destportstr = NULL;
       char *urlptr = NULL;
   
       void *sconf = r->server->module_config;
       proxy_server_conf *conf =
  -        (proxy_server_conf *)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;
  +    (proxy_server_conf *) 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;
   
       memset(&server, '\0', sizeof(server));
  @@ -170,78 +176,76 @@
   
   /* We break the URL into host, port, path-search */
   
  -    urlptr = strstr(url,"://");
  -    if (urlptr == NULL) return BAD_REQUEST;
  +    urlptr = strstr(url, "://");
  +    if (urlptr == NULL)
  +	return BAD_REQUEST;
       urlptr += 3;
       destport = DEFAULT_PORT;
       p = strchr(urlptr, '/');
  -    if (p == NULL)
  -    {
  -        desthost = pstrdup(pool, urlptr);
  -        urlptr = "/";
  -    } else
  -    {
  -        char *q = palloc(pool, p-urlptr+1);
  -        memcpy(q, urlptr, p-urlptr);
  -        q[p-urlptr] = '\0';
  -        urlptr = p;
  -        desthost = q;
  +    if (p == NULL) {
  +	desthost = pstrdup(pool, urlptr);
  +	urlptr = "/";
  +    }
  +    else {
  +	char *q = palloc(pool, p - urlptr + 1);
  +	memcpy(q, urlptr, p - urlptr);
  +	q[p - urlptr] = '\0';
  +	urlptr = p;
  +	desthost = q;
       }
   
       p = strchr(desthost, ':');
  -    if (p != NULL)
  -    {
  -        *(p++) = '\0';
  -	if (isdigit(*p))
  -	{
  -            destport = atoi(p);
  -            destportstr = p;
  +    if (p != NULL) {
  +	*(p++) = '\0';
  +	if (isdigit(*p)) {
  +	    destport = atoi(p);
  +	    destportstr = p;
   	}
       }
   
   /* check if ProxyBlock directive on this host */
       destaddr.s_addr = ap_inet_addr(desthost);
  -    for (i=0; i < conf->noproxies->nelts; i++)
  -    {
  -        if ((npent[i].name != NULL && strstr(desthost, npent[i].name) != NULL)
  -	  || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
  +    for (i = 0; i < conf->noproxies->nelts; i++) {
  +	if ((npent[i].name != NULL && strstr(desthost, npent[i].name) != NULL)
  +	    || destaddr.s_addr == npent[i].addr.s_addr || npent[i].name[0] == '*')
   	    return proxyerror(r, "Connect to remote machine blocked");
       }
   
  -    if (proxyhost != NULL)
  -    {
  +    if (proxyhost != NULL) {
   	server.sin_port = htons(proxyport);
   	err = proxy_host2addr(proxyhost, &server_hp);
  -	if (err != NULL) return DECLINED;  /* try another */
  -    } else
  -    {
  +	if (err != NULL)
  +	    return DECLINED;	/* try another */
  +    }
  +    else {
   	server.sin_port = htons(destport);
   	err = proxy_host2addr(desthost, &server_hp);
  -	if (err != NULL) return proxyerror(r, err); /* give up */
  +	if (err != NULL)
  +	    return proxyerror(r, err);	/* give up */
       }
   
       sock = psocket(pool, PF_INET, SOCK_STREAM, IPPROTO_TCP);
  -    if (sock == -1)
  -    {
  +    if (sock == -1) {
   	aplog_error(APLOG_MARK, APLOG_ERR, r->server,
   		    "proxy: error creating socket");
   	return SERVER_ERROR;
       }
  -    
  +
       if (conf->recv_buffer_size) {
  -      if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
  -		     (const char *)&conf->recv_buffer_size, sizeof(int))
  -	  == -1) {
  -	proxy_log_uerror("setsockopt", "(SO_RCVBUF)",
  -			 "Failed to set RecvBufferSize, using default",
  -			 r->server);
  -      }
  +	if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
  +		       (const char *) &conf->recv_buffer_size, sizeof(int))
  +	    == -1) {
  +	    proxy_log_uerror("setsockopt", "(SO_RCVBUF)",
  +			     "Failed to set RecvBufferSize, using default",
  +			     r->server);
  +	}
       }
   
   #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) {
  +	for (; ip_addr->s_addr != 0; ++ip_addr) {
   	    memcpy(&server.sin_addr, ip_addr, sizeof(struct in_addr));
   	    i = proxy_doconnect(sock, &server, r);
   	    if (i == 0)
  @@ -252,17 +256,18 @@
       j = 0;
       while (server_hp.h_addr_list[j] != NULL) {
   	memcpy(&server.sin_addr, server_hp.h_addr_list[j],
  -	    sizeof(struct in_addr));
  -        i = proxy_doconnect(sock, &server, r);
  +	       sizeof(struct in_addr));
  +	i = proxy_doconnect(sock, &server, r);
   	if (i == 0)
   	    break;
   	j++;
       }
   #endif
  -    if (i == -1)
  -    {
  -	if (proxyhost != NULL) return DECLINED; /* try again another way */
  -	else return proxyerror(r, "Could not connect to remote machine");
  +    if (i == -1) {
  +	if (proxyhost != NULL)
  +	    return DECLINED;	/* try again another way */
  +	else
  +	    return proxyerror(r, "Could not connect to remote machine");
       }
   
       clear_connection(r->headers_in);	/* Strip connection-based headers */
  @@ -270,23 +275,22 @@
       f = bcreate(pool, B_RDWR | B_SOCKET);
       bpushfd(f, sock, sock);
   
  -    hard_timeout ("proxy send", r);
  +    hard_timeout("proxy send", r);
       bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.0\015\012",
  -           NULL);
  +	   NULL);
       bvputs(f, "Host: ", desthost, NULL);
       if (destportstr != NULL && destport != DEFAULT_PORT)
   	bvputs(f, ":", destportstr, "\015\012", NULL);
       else
   	bputs("\015\012", f);
   
  -    reqhdrs_arr = table_elts (r->headers_in);
  -    reqhdrs = (table_entry *)reqhdrs_arr->elts;
  -    for (i=0; i < reqhdrs_arr->nelts; i++)
  -    {
  +    reqhdrs_arr = table_elts(r->headers_in);
  +    reqhdrs = (table_entry *) reqhdrs_arr->elts;
  +    for (i = 0; i < reqhdrs_arr->nelts; i++) {
   	if (reqhdrs[i].key == NULL || reqhdrs[i].val == NULL
  -	    /* Clear out headers not to send */
  -	  || !strcasecmp(reqhdrs[i].key, "Host") /* Already sent */
  -	  || !strcasecmp(reqhdrs[i].key, "Proxy-Authorization"))
  +	/* Clear out headers not to send */
  +	    || !strcasecmp(reqhdrs[i].key, "Host")	/* Already sent */
  +	    ||!strcasecmp(reqhdrs[i].key, "Proxy-Authorization"))
   	    continue;
   	bvputs(f, reqhdrs[i].key, ": ", reqhdrs[i].val, "\015\012", NULL);
       }
  @@ -294,30 +298,26 @@
       bputs("\015\012", f);
   /* send the request data, if any. N.B. should we trap SIGPIPE ? */
   
  -    if (should_client_block(r))
  -    {
  +    if (should_client_block(r)) {
   	while ((i = get_client_block(r, buffer, HUGE_STRING_LEN)) > 0)
  -            bwrite(f, buffer, i);
  +	    bwrite(f, buffer, i);
       }
       bflush(f);
       kill_timeout(r);
   
  -    hard_timeout ("proxy receive", r);
  -    
  -    len = bgets(buffer, HUGE_STRING_LEN-1, f);
  -    if (len == -1 || len == 0)
  -    {
  +    hard_timeout("proxy receive", r);
  +
  +    len = bgets(buffer, HUGE_STRING_LEN - 1, f);
  +    if (len == -1 || len == 0) {
   	bclose(f);
   	kill_timeout(r);
   	return proxyerror(r, "Error reading from remote server");
       }
   
   /* Is it an HTTP/1 response?  This is buggy if we ever see an HTTP/1.10 */
  -    if (checkmask(buffer,  "HTTP/#.# ###*"))
  -    {
  +    if (checkmask(buffer, "HTTP/#.# ###*")) {
   /* If not an HTTP/1 messsage or if the status line was > 8192 bytes */
  -	if (buffer[5] != '1' || buffer[len-1] != '\n')
  -	{
  +	if (buffer[5] != '1' || buffer[len - 1] != '\n') {
   	    bclose(f);
   	    kill_timeout(r);
   	    return BAD_GATEWAY;
  @@ -336,10 +336,9 @@
   
   	resp_hdrs = proxy_read_headers(pool, buffer, HUGE_STRING_LEN, f);
   
  -	clear_connection((table *)resp_hdrs);  /* Strip Connection hdrs */
  +	clear_connection((table *) resp_hdrs);	/* Strip Connection hdrs */
       }
  -    else
  -    {
  +    else {
   /* an http/0.9 response */
   	backasswards = 1;
   	r->status = 200;
  @@ -355,11 +354,11 @@
    * HTTP/1.0 requires us to accept 3 types of dates, but only generate
    * one type
    */
  -    
  -    hdr = (struct hdr_entry *)resp_hdrs->elts;
  -    for (i=0; i < resp_hdrs->nelts; i++)
  -    {
  -	if (hdr[i].value[0] == '\0') continue;
  +
  +    hdr = (struct hdr_entry *) resp_hdrs->elts;
  +    for (i = 0; i < resp_hdrs->nelts; i++) {
  +	if (hdr[i].value[0] == '\0')
  +	    continue;
   	p = hdr[i].field;
   	if (strcasecmp(p, "Date") == 0 ||
   	    strcasecmp(p, "Last-Modified") == 0 ||
  @@ -368,36 +367,34 @@
       }
   
   /* check if NoCache directive on this host */
  -    for (i=0; i < conf->nocaches->nelts; i++)
  -    {
  -        if ((ncent[i].name != NULL && strstr(desthost, ncent[i].name) != NULL)
  -	  || destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
  -	    nocache = 1; 
  +    for (i = 0; i < conf->nocaches->nelts; i++) {
  +	if ((ncent[i].name != NULL && strstr(desthost, ncent[i].name) != NULL)
  +	    || destaddr.s_addr == ncent[i].addr.s_addr || ncent[i].name[0] == '*')
  +	    nocache = 1;
       }
   
       i = proxy_cache_update(c, resp_hdrs, !backasswards, nocache);
  -    if (i != DECLINED)
  -    {
  +    if (i != DECLINED) {
   	bclose(f);
   	return i;
       }
   
       cache = c->fp;
   
  -    hard_timeout ("proxy receive", r);
  +    hard_timeout("proxy receive", r);
   
   /* write status line */
       if (!r->assbackwards)
  -        rvputs(r, "HTTP/1.0 ", r->status_line, "\015\012", NULL);
  +	rvputs(r, "HTTP/1.0 ", r->status_line, "\015\012", NULL);
       if (cache != NULL)
   	if (bvputs(cache, "HTTP/1.0 ", r->status_line, "\015\012", NULL) == -1)
   	    cache = proxy_cache_error(c);
   
   /* send headers */
  -    for (i=0; i < resp_hdrs->nelts; i++)
  -    {
  +    for (i = 0; i < resp_hdrs->nelts; i++) {
   	if (hdr[i].field == NULL || hdr[i].value == NULL ||
  -	    hdr[i].value[0] == '\0') continue;
  +	    hdr[i].value[0] == '\0')
  +	    continue;
   	if (!r->assbackwards) {
   	    rvputs(r, hdr[i].field, ": ", hdr[i].value, "\015\012", NULL);
   	    table_set(r->headers_out, hdr[i].field, hdr[i].value);
  @@ -408,25 +405,28 @@
   		cache = proxy_cache_error(c);
       }
   
  -    if (!r->assbackwards) rputs("\015\012", r);
  +    if (!r->assbackwards)
  +	rputs("\015\012", r);
       if (cache != NULL)
  -	if (bputs("\015\012", cache) == -1) cache = proxy_cache_error(c);
  +	if (bputs("\015\012", cache) == -1)
  +	    cache = proxy_cache_error(c);
   
       bsetopt(r->connection->client, BO_BYTECT, &zero);
       r->sent_bodyct = 1;
   /* Is it an HTTP/0.9 respose? If so, send the extra data */
  -    if (backasswards)
  -    {
  +    if (backasswards) {
   	bwrite(r->connection->client, buffer, len);
   	if (cache != NULL)
  -	    if (bwrite(f, buffer, len) != len) cache = proxy_cache_error(c);
  +	    if (bwrite(f, buffer, len) != len)
  +		cache = proxy_cache_error(c);
       }
       kill_timeout(r);
   
   /* send body */
   /* if header only, then cache will be NULL */
   /* HTTP/1.0 tells us to read to EOF, rather than content-length bytes */
  -    if (!r->header_only) proxy_send_fb(f, r, cache, c);
  +    if (!r->header_only)
  +	proxy_send_fb(f, r, cache, c);
   
       proxy_cache_tidy(c);
   
  @@ -435,4 +435,3 @@
       proxy_garbage_coll(r);
       return OK;
   }
  -
  
  
  
  1.31      +369 -377  apachen/src/modules/proxy/proxy_util.c
  
  Index: proxy_util.c
  ===================================================================
  RCS file: /export/home/cvs/apachen/src/modules/proxy/proxy_util.c,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- proxy_util.c	1997/09/14 07:34:38	1.30
  +++ proxy_util.c	1997/09/16 00:59:41	1.31
  @@ -64,37 +64,45 @@
   static int proxy_match_word(struct dirconn_entry *This, request_rec *r);
   
   /* already called in the knowledge that the characters are hex digits */
  -int
  -proxy_hex2c(const char *x)
  +int proxy_hex2c(const char *x)
   {
       int i, ch;
   
       ch = x[0];
  -    if (isdigit(ch)) i = ch - '0';
  -    else if (isupper(ch)) i = ch - ('A' - 10);
  -    else i = ch - ('a' - 10);
  +    if (isdigit(ch))
  +	i = ch - '0';
  +    else if (isupper(ch))
  +	i = ch - ('A' - 10);
  +    else
  +	i = ch - ('a' - 10);
       i <<= 4;
   
       ch = x[1];
  -    if (isdigit(ch)) i += ch - '0';
  -    else if (isupper(ch)) i += ch - ('A' - 10);
  -    else i += ch - ('a' - 10);
  +    if (isdigit(ch))
  +	i += ch - '0';
  +    else if (isupper(ch))
  +	i += ch - ('A' - 10);
  +    else
  +	i += ch - ('a' - 10);
       return i;
   }
   
  -void
  -proxy_c2hex(int ch, char *x)
  +void proxy_c2hex(int ch, char *x)
   {
       int i;
   
       x[0] = '%';
       i = (ch & 0xF0) >> 4;
  -    if (i >= 10) x[1] = ('A' - 10) + i;
  -    else x[1] = '0' + i;
  +    if (i >= 10)
  +	x[1] = ('A' - 10) + i;
  +    else
  +	x[1] = '0' + i;
   
       i = ch & 0x0F;
  -    if (i >= 10) x[2] = ('A' - 10) + i;
  -    else x[2] = '0' + i;
  +    if (i >= 10)
  +	x[2] = ('A' - 10) + i;
  +    else
  +	x[2] = '0' + i;
   }
   
   /*
  @@ -108,12 +116,12 @@
    * those which must not be touched.
    */
   char *
  -proxy_canonenc(pool *p, const char *x, int len, enum enctype t, int isenc)
  +     proxy_canonenc(pool *p, const char *x, int len, enum enctype t, int isenc)
   {
       int i, j, ch;
       char *y;
  -    const char *allowed;  /* characters which should not be encoded */
  -    const char *reserved;  /* characters which much not be en/de-coded */
  +    const char *allowed;	/* characters which should not be encoded */
  +    const char *reserved;	/* characters which much not be en/de-coded */
   
   /* N.B. in addition to :@&=, this allows ';' in an http path
    * and '?' in an ftp path -- this may be revised
  @@ -122,47 +130,52 @@
    * it may be form-encoded. (Although RFC 1738 doesn't allow this -
    * it only permits ; / ? : @ = & as reserved chars.)
    */
  -    if (t == enc_path) allowed = "$-_.+!*'(),;:@&=";
  -    else if (t == enc_search) allowed = "$-_.!*'(),;:@&=";
  -    else if (t == enc_user) allowed = "$-_.+!*'(),;@&=";
  -    else if (t == enc_fpath) allowed = "$-_.+!*'(),?:@&=";
  -    else /* if (t == enc_parm) */ allowed = "$-_.+!*'(),?/:@&=";
  -
  -    if (t == enc_path) reserved = "/";
  -    else if (t == enc_search) reserved = "+";
  -    else reserved = "";
  +    if (t == enc_path)
  +	allowed = "$-_.+!*'(),;:@&=";
  +    else if (t == enc_search)
  +	allowed = "$-_.!*'(),;:@&=";
  +    else if (t == enc_user)
  +	allowed = "$-_.+!*'(),;@&=";
  +    else if (t == enc_fpath)
  +	allowed = "$-_.+!*'(),?:@&=";
  +    else			/* if (t == enc_parm) */
  +	allowed = "$-_.+!*'(),?/:@&=";
  +
  +    if (t == enc_path)
  +	reserved = "/";
  +    else if (t == enc_search)
  +	reserved = "+";
  +    else
  +	reserved = "";
   
  -    y = palloc(p, 3*len+1);
  +    y = palloc(p, 3 * len + 1);
   
  -    for (i=0, j=0; i < len; i++, j++)
  -    {
  +    for (i = 0, j = 0; i < len; i++, j++) {
   /* always handle '/' first */
   	ch = x[i];
  -	if (ind(reserved, ch) != -1)
  -	{
  +	if (ind(reserved, ch) != -1) {
   	    y[j] = ch;
   	    continue;
   	}
   /* decode it if not already done */
  -	if (isenc && ch == '%')
  -	{
  -	    if (!isxdigit(x[i+1]) || !isxdigit(x[i+2]))
  +	if (isenc && ch == '%') {
  +	    if (!isxdigit(x[i + 1]) || !isxdigit(x[i + 2]))
   		return NULL;
  -	    ch = proxy_hex2c(&x[i+1]);
  +	    ch = proxy_hex2c(&x[i + 1]);
   	    i += 2;
  -	    if (ch != 0 && ind(reserved, ch) != -1)
  -	    {  /* keep it encoded */
  +	    if (ch != 0 && ind(reserved, ch) != -1) {	/* keep it encoded */
   		proxy_c2hex(ch, &y[j]);
   		j += 2;
   		continue;
   	    }
   	}
   /* recode it, if necessary */
  -	if (!isalnum(ch) && ind(allowed, ch) == -1)
  -	{
  +	if (!isalnum(ch) && ind(allowed, ch) == -1) {
   	    proxy_c2hex(ch, &y[j]);
   	    j += 2;
  -	} else y[j] = ch;
  +	}
  +	else
  +	    y[j] = ch;
       }
       y[j] = '\0';
       return y;
  @@ -179,91 +192,92 @@
    * Returns an error string.
    */
   char *
  -proxy_canon_netloc(pool *pool, char **const urlp, char **userp,
  -    char **passwordp, char **hostp, int *port)
  +     proxy_canon_netloc(pool *pool, char **const urlp, char **userp,
  +			char **passwordp, char **hostp, int *port)
   {
       int i;
  -    char *p, *host, *url=*urlp;
  +    char *p, *host, *url = *urlp;
   
  -    if (url[0] != '/' || url[1] != '/') return "Malformed URL";
  +    if (url[0] != '/' || url[1] != '/')
  +	return "Malformed URL";
       host = url + 2;
       url = strchr(host, '/');
       if (url == NULL)
   	url = "";
       else
  -	*(url++) = '\0';  /* skip seperating '/' */
  +	*(url++) = '\0';	/* skip seperating '/' */
   
  -    if (userp != NULL)
  -    {
  -	char *user=NULL, *password = NULL;
  +    if (userp != NULL) {
  +	char *user = NULL, *password = NULL;
   	p = strchr(host, '@');
   
  -	if (p != NULL)
  -	{
  +	if (p != NULL) {
   	    *p = '\0';
   	    user = host;
   	    host = p + 1;
   
   /* find password */
   	    p = strchr(user, ':');
  -	    if (p != NULL)
  -	    {
  +	    if (p != NULL) {
   		*p = '\0';
  -		password = proxy_canonenc(pool, p+1, strlen(p+1), enc_user, 1);
  +		password = proxy_canonenc(pool, p + 1, strlen(p + 1), enc_user, 1);
   		if (password == NULL)
   		    return "Bad %-escape in URL (password)";
   	    }
   
   	    user = proxy_canonenc(pool, user, strlen(user), enc_user, 1);
  -	    if (user == NULL) return "Bad %-escape in URL (username)";
  +	    if (user == NULL)
  +		return "Bad %-escape in URL (username)";
   	}
   	*userp = user;
   	*passwordp = password;
       }
   
       p = strchr(host, ':');
  -    if (p != NULL)
  -    {
  +    if (p != NULL) {
   	*(p++) = '\0';
  -	
  -	for (i=0; p[i] != '\0'; i++)
  -	    if (!isdigit(p[i])) break;
  +
  +	for (i = 0; p[i] != '\0'; i++)
  +	    if (!isdigit(p[i]))
  +		break;
   
   	if (i == 0 || p[i] != '\0')
   	    return "Bad port number in URL";
   	*port = atoi(p);
  -	if (*port > 65535) return "Port number in URL > 65535";
  +	if (*port > 65535)
  +	    return "Port number in URL > 65535";
       }
  -    str_tolower(host); /* DNS names are case-insensitive */
  -    if (*host == '\0') return "Missing host in URL";
  +    str_tolower(host);		/* DNS names are case-insensitive */
  +    if (*host == '\0')
  +	return "Missing host in URL";
   /* check hostname syntax */
  -    for (i=0; host[i] != '\0'; i++)
  +    for (i = 0; host[i] != '\0'; i++)
   	if (!isdigit(host[i]) && host[i] != '.')
   	    break;
  - /* must be an IP address */
  +    /* must be an IP address */
   #ifdef WIN32
       if (host[i] == '\0' && (inet_addr(host) == -1))
   #else
       if (host[i] == '\0' && (ap_inet_addr(host) == -1 || inet_network(host) == -1))
   #endif
       {
  -	    return "Bad IP address in URL";
  +	return "Bad IP address in URL";
       }
   
   /*    if (strchr(host,'.') == NULL && domain != NULL)
  -	host = pstrcat(pool, host, domain, NULL);
  -*/
  +   host = pstrcat(pool, host, domain, NULL);
  + */
       *urlp = url;
       *hostp = host;
   
       return NULL;
   }
   
  -static const char *lwday[7]=
  +static const char *lwday[7] =
   {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  -static const char *wday[7]=
  +static const char *wday[7] =
   {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  -static const char *months[12]=
  +static const char *months[12] =
   {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
    "Dec"};
   
  @@ -275,45 +289,58 @@
    * formatted, then it exits very quickly.
    */
   char *
  -proxy_date_canon(pool *p, char *x)
  +     proxy_date_canon(pool *p, char *x)
   {
       int wk, mday, year, hour, min, sec, mon;
       char *q, month[4], zone[4], week[4];
  -    
  +
       q = strchr(x, ',');
       /* check for RFC 850 date */
  -    if (q != NULL && q - x > 3 && q[1] == ' ')
  -    {
  +    if (q != NULL && q - x > 3 && q[1] == ' ') {
   	*q = '\0';
  -	for (wk=0; wk < 7; wk++)
  -	    if (strcmp(x, lwday[wk]) == 0) break;
  +	for (wk = 0; wk < 7; wk++)
  +	    if (strcmp(x, lwday[wk]) == 0)
  +		break;
   	*q = ',';
  -	if (wk == 7) return x;  /* not a valid date */
  +	if (wk == 7)
  +	    return x;		/* not a valid date */
   	if (q[4] != '-' || q[8] != '-' || q[11] != ' ' || q[14] != ':' ||
  -	    q[17] != ':' || strcmp(&q[20], " GMT") != 0) return x;
  -	if (sscanf(q+2, "%u-%3s-%u %u:%u:%u %3s", &mday, month, &year,
  -		   &hour, &min, &sec, zone) != 7) return x;
  -	if (year < 70) year += 2000;
  -	else year += 1900;
  -    } else
  -    {
  +	    q[17] != ':' || strcmp(&q[20], " GMT") != 0)
  +	    return x;
  +	if (sscanf(q + 2, "%u-%3s-%u %u:%u:%u %3s", &mday, month, &year,
  +		   &hour, &min, &sec, zone) != 7)
  +	    return x;
  +	if (year < 70)
  +	    year += 2000;
  +	else
  +	    year += 1900;
  +    }
  +    else {
   /* check for acstime() date */
   	if (x[3] != ' ' || x[7] != ' ' || x[10] != ' ' || x[13] != ':' ||
  -	    x[16] != ':' || x[19] != ' ' || x[24] != '\0') return x;
  +	    x[16] != ':' || x[19] != ' ' || x[24] != '\0')
  +	    return x;
   	if (sscanf(x, "%3s %3s %u %u:%u:%u %u", week, month, &mday, &hour,
  -		   &min, &sec, &year) != 7) return x;
  -	for (wk=0; wk < 7; wk++)
  -	    if (strcmp(week, wday[wk]) == 0) break;
  -	if (wk == 7) return x;
  +		   &min, &sec, &year) != 7)
  +	    return x;
  +	for (wk = 0; wk < 7; wk++)
  +	    if (strcmp(week, wday[wk]) == 0)
  +		break;
  +	if (wk == 7)
  +	    return x;
       }
   
   /* check date */
  -    for (mon=0; mon < 12; mon++) if (strcmp(month, months[mon]) == 0) break;
  -    if (mon == 12) return x;
  +    for (mon = 0; mon < 12; mon++)
  +	if (strcmp(month, months[mon]) == 0)
  +	    break;
  +    if (mon == 12)
  +	return x;
   
  -    if (strlen(x) < 31) x = palloc(p, 31);
  -    ap_snprintf(x, strlen(x)+1, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", wday[wk], mday,
  -	    months[mon], year, hour, min, sec);
  +    if (strlen(x) < 31)
  +	x = palloc(p, 31);
  +    ap_snprintf(x, strlen(x) + 1, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", wday[wk], mday,
  +		months[mon], year, hour, min, sec);
       return x;
   }
   
  @@ -322,7 +349,7 @@
    * Returns NULL on file error
    */
   array_header *
  -proxy_read_headers(pool *pool, char *buffer, int size, BUFF *f)
  +             proxy_read_headers(pool *pool, char *buffer, int size, BUFF *f)
   {
       int gotcr, len, i, j;
       array_header *resp_hdrs;
  @@ -333,45 +360,43 @@
       hdr = NULL;
   
       gotcr = 1;
  -    for (;;)
  -    {
  +    for (;;) {
   	len = bgets(buffer, size, f);
  -	if (len == -1) return NULL;
  -	if (len == 0) break;
  -	if (buffer[len-1] == '\n')
  -	{
  +	if (len == -1)
  +	    return NULL;
  +	if (len == 0)
  +	    break;
  +	if (buffer[len - 1] == '\n') {
   	    buffer[--len] = '\0';
   	    i = 1;
  -	} else
  +	}
  +	else
   	    i = 0;
   
  -	if (!gotcr || buffer[0] == ' ' || buffer[0] == '\t')
  -	{
  +	if (!gotcr || buffer[0] == ' ' || buffer[0] == '\t') {
   	    /* a continuation header */
  -	    if (hdr == NULL)
  -	    {
  +	    if (hdr == NULL) {
   		/* error!! */
  -		if (!i)
  -		{
  +		if (!i) {
   		    i = bskiplf(f);
  -		    if (i == -1) return NULL;
  +		    if (i == -1)
  +			return NULL;
   		}
   		gotcr = 1;
   		continue;
   	    }
   	    hdr->value = pstrcat(pool, hdr->value, buffer, NULL);
   	}
  -	else if (gotcr && len == 0) break;
  -	else
  -	{
  +	else if (gotcr && len == 0)
  +	    break;
  +	else {
   	    p = strchr(buffer, ':');
  -	    if (p == NULL)
  -	    {
  +	    if (p == NULL) {
   		/* error!! */
  -		if (!gotcr)
  -		{
  +		if (!gotcr) {
   		    i = bskiplf(f);
  -		    if (i == -1) return NULL;
  +		    if (i == -1)
  +			return NULL;
   		}
   		gotcr = 1;
   		hdr = NULL;
  @@ -380,32 +405,32 @@
   	    hdr = push_array(resp_hdrs);
   	    *(p++) = '\0';
   	    hdr->field = pstrdup(pool, buffer);
  -	    while (*p == ' ' || *p == '\t') p++;
  +	    while (*p == ' ' || *p == '\t')
  +		p++;
   	    hdr->value = pstrdup(pool, p);
   	    gotcr = i;
   	}
       }
   
  -    hdr = (struct hdr_entry *)resp_hdrs->elts;
  -    for (i=0; i < resp_hdrs->nelts; i++)
  -    {
  +    hdr = (struct hdr_entry *) resp_hdrs->elts;
  +    for (i = 0; i < resp_hdrs->nelts; i++) {
   	p = hdr[i].value;
   	j = strlen(p);
  -	while (j > 0 && (p[j-1] == ' ' || p[j-1] == '\t')) j--;
  +	while (j > 0 && (p[j - 1] == ' ' || p[j - 1] == '\t'))
  +	    j--;
   	p[j] = '\0';
       }
   
       return resp_hdrs;
   }
   
  -long int
  -proxy_send_fb(BUFF *f, request_rec *r, BUFF *f2, struct cache_req *c)
  +long int proxy_send_fb(BUFF *f, request_rec *r, BUFF *f2, struct cache_req *c)
   {
       char buf[IOBUFSIZE];
       long total_bytes_sent;
  -    register int n,o,w;
  +    register int n, o, w;
       conn_rec *con = r->connection;
  -    
  +
       total_bytes_sent = 0;
   
       /* Since we are reading from one buffer and writing to another,
  @@ -416,38 +441,40 @@
   
       while (!con->aborted && f != NULL) {
   	n = bread(f, buf, IOBUFSIZE);
  -	if (n == -1) /* input error */
  -	{
  -	    if (f2 != NULL) f2 = proxy_cache_error(c);
  +	if (n == -1) {		/* input error */
  +	    if (f2 != NULL)
  +		f2 = proxy_cache_error(c);
   	    break;
   	}
  -	if (n == 0) break; /* EOF */
  -        o=0;
  +	if (n == 0)
  +	    break;		/* EOF */
  +	o = 0;
   	total_bytes_sent += n;
   
   	if (f2 != NULL)
  -	    if (bwrite(f2, buf, n) != n) f2 = proxy_cache_error(c);
  -	
  -        while(n && !con->aborted) {
  -            w = bwrite(con->client, &buf[o], n);
  -            if (w <= 0) {
  -                if (f2 != NULL) {
  -                    pclosef(c->req->pool, c->fp->fd);
  -                    c->fp = NULL; 
  -                    f2 = NULL;
  -                    con->aborted = 1;
  -                    unlink(c->tempfile);
  -                }
  -                break;
  -            }
  -	    reset_timeout(r); /* reset timeout after successful write */
  -            n-=w;
  -            o+=w;
  -        }
  +	    if (bwrite(f2, buf, n) != n)
  +		f2 = proxy_cache_error(c);
  +
  +	while (n && !con->aborted) {
  +	    w = bwrite(con->client, &buf[o], n);
  +	    if (w <= 0) {
  +		if (f2 != NULL) {
  +		    pclosef(c->req->pool, c->fp->fd);
  +		    c->fp = NULL;
  +		    f2 = NULL;
  +		    con->aborted = 1;
  +		    unlink(c->tempfile);
  +		}
  +		break;
  +	    }
  +	    reset_timeout(r);	/* reset timeout after successful write */
  +	    n -= w;
  +	    o += w;
  +	}
       }
       if (!con->aborted)
  -        bflush(con->client);
  -    
  +	bflush(con->client);
  +
       kill_timeout(r);
       return total_bytes_sent;
   }
  @@ -456,14 +483,14 @@
    * Read a header from the array, returning the first entry
    */
   struct hdr_entry *
  -proxy_get_header(array_header *hdrs_arr, const char *name)
  +          proxy_get_header(array_header *hdrs_arr, const char *name)
   {
       struct hdr_entry *hdrs;
       int i;
   
  -    hdrs = (struct hdr_entry *)hdrs_arr->elts;
  +    hdrs = (struct hdr_entry *) hdrs_arr->elts;
       for (i = 0; i < hdrs_arr->nelts; i++)
  -        if (hdrs[i].field != NULL && strcasecmp(name, hdrs[i].field) == 0)
  +	if (hdrs[i].field != NULL && strcasecmp(name, hdrs[i].field) == 0)
   	    return &hdrs[i];
   
       return NULL;
  @@ -475,21 +502,20 @@
    * is not subsequently overwritten
    */
   struct hdr_entry *
  -proxy_add_header(array_header *hdrs_arr, char *field, char *value,
  -	   int rep)
  +          proxy_add_header(array_header *hdrs_arr, char *field, char *value,
  +			   int rep)
   {
       int i;
       struct hdr_entry *hdrs;
   
  -    hdrs = (struct hdr_entry *)hdrs_arr->elts;
  +    hdrs = (struct hdr_entry *) hdrs_arr->elts;
       if (rep)
   	for (i = 0; i < hdrs_arr->nelts; i++)
  -	    if (hdrs[i].field != NULL && strcasecmp(field, hdrs[i].field) == 0)
  -	    {
  +	    if (hdrs[i].field != NULL && strcasecmp(field, hdrs[i].field) == 0) {
   		hdrs[i].value = value;
   		return hdrs;
   	    }
  -	
  +
       hdrs = push_array(hdrs_arr);
       hdrs->field = field;
       hdrs->value = value;
  @@ -497,13 +523,12 @@
       return hdrs;
   }
   
  -void
  -proxy_del_header(array_header *hdrs_arr, const char *field)
  +void proxy_del_header(array_header *hdrs_arr, const char *field)
   {
       int i;
       struct hdr_entry *hdrs;
   
  -    hdrs = (struct hdr_entry *)hdrs_arr->elts;
  +    hdrs = (struct hdr_entry *) hdrs_arr->elts;
   
       for (i = 0; i < hdrs_arr->nelts; i++)
   	if (hdrs[i].field != NULL && strcasecmp(field, hdrs[i].field) == 0)
  @@ -517,20 +542,19 @@
    * 
    * A timeout should be set before calling this routine.
    */
  -void
  -proxy_send_headers(request_rec *r, const char *respline, array_header *hdrs_arr)
  +void proxy_send_headers(request_rec *r, const char *respline, array_header *hdrs_arr)
   {
       struct hdr_entry *hdrs;
       int i;
       BUFF *fp = r->connection->client;
   
  -    hdrs = (struct hdr_entry *)hdrs_arr->elts;
  +    hdrs = (struct hdr_entry *) hdrs_arr->elts;
   
       bputs(respline, fp);
       bputs("\015\012", fp);
  -    for (i = 0; i < hdrs_arr->nelts; i++)
  -    {
  -        if (hdrs[i].field == NULL) continue;
  +    for (i = 0; i < hdrs_arr->nelts; i++) {
  +	if (hdrs[i].field == NULL)
  +	    continue;
   	bvputs(fp, hdrs[i].field, ": ", hdrs[i].value, "\015\012", NULL);
   	table_set(r->headers_out, hdrs[i].field, hdrs[i].value);
       }
  @@ -545,27 +569,28 @@
    * The return returns 1 if the token val is found in the list, or 0
    * otherwise.
    */
  -int
  -proxy_liststr(const char *list, const char *val)
  +int proxy_liststr(const char *list, const char *val)
   {
       int len, i;
       const char *p;
   
       len = strlen(val);
   
  -    while (list != NULL)
  -    {
  +    while (list != NULL) {
   	p = strchr(list, ',');
  -	if (p != NULL)
  -	{
  +	if (p != NULL) {
   	    i = p - list;
  -	    do p++; while (isspace(*p));
  -	} 
  +	    do
  +		p++;
  +	    while (isspace(*p));
  +	}
   	else
   	    i = strlen(list);
   
  -	while (i > 0 && isspace(list[i-1])) i--;
  -	if (i == len && strncasecmp(list, val, len) == 0) return 1;
  +	while (i > 0 && isspace(list[i - 1]))
  +	    i--;
  +	if (i == len && strncasecmp(list, val, len) == 0)
  +	    return 1;
   	list = p;
       }
       return 0;
  @@ -577,78 +602,73 @@
    * On NT, the file system is NOT case sensitive. So, a == A
    * need to map to smaller set of characters
    */
  -void
  -proxy_hash(const char *it, char *val,int ndepth,int nlength)
  +void proxy_hash(const char *it, char *val, int ndepth, int nlength)
   {
       AP_MD5_CTX context;
       unsigned char digest[16];
       char tmp[26];
       int i, k, d;
       unsigned int x;
  -    static const char table[32]= "abcdefghijklmnopqrstuvwxyz012345";
  +    static const char table[32] = "abcdefghijklmnopqrstuvwxyz012345";
   
       MD5Init(&context);
  -    MD5Update(&context, (const unsigned char *)it, strlen(it));
  +    MD5Update(&context, (const unsigned char *) it, strlen(it));
       MD5Final(digest, &context);
   
   /* encode 128 bits as 26 characters, using a modified uuencoding */
   /* the encoding is 5 bytes -> 8 characters
    * i.e. 128 bits is 3 x 5 bytes + 1 byte -> 3 * 8 characters + 2 characters
    */
  -    for (i=0, k=0; i < 15; i += 5)
  -    {
  -	x = (digest[i] << 24) | (digest[i+1] << 16) | (digest[i+2] << 8) | digest[i+3];
  +    for (i = 0, k = 0; i < 15; i += 5) {
  +	x = (digest[i] << 24) | (digest[i + 1] << 16) | (digest[i + 2] << 8) | digest[i + 3];
   	tmp[k++] = table[x >> 27];
   	tmp[k++] = table[(x >> 22) & 0x1f];
   	tmp[k++] = table[(x >> 17) & 0x1f];
  -        tmp[k++] = table[(x >> 12) & 0x1f];
  -        tmp[k++] = table[(x >> 7) & 0x1f];
  -        tmp[k++] = table[(x >> 2) & 0x1f];
  -        x = ((x & 0x3) << 8) | digest[i+4];
  -        tmp[k++] = table[x >> 5];
  +	tmp[k++] = table[(x >> 12) & 0x1f];
  +	tmp[k++] = table[(x >> 7) & 0x1f];
  +	tmp[k++] = table[(x >> 2) & 0x1f];
  +	x = ((x & 0x3) << 8) | digest[i + 4];
  +	tmp[k++] = table[x >> 5];
   	tmp[k++] = table[x & 0x1f];
       }
   /* one byte left */
       x = digest[15];
  -    tmp[k++] = table[x >> 3];  /* use up 5 bits */
  +    tmp[k++] = table[x >> 3];	/* use up 5 bits */
       tmp[k++] = table[x & 0x7];
       /* now split into directory levels */
   
  -    for(i=k=d=0 ; d < ndepth ; ++d)
  -	{
  -	strncpy(&val[i],&tmp[k],nlength);
  -	k+=nlength;
  -	val[i+nlength]='/';
  -	i+=nlength+1;
  -	}
  -    memcpy(&val[i],&tmp[k],22-k);
  -    val[i+22-k]='\0';
  +    for (i = k = d = 0; d < ndepth; ++d) {
  +	strncpy(&val[i], &tmp[k], nlength);
  +	k += nlength;
  +	val[i + nlength] = '/';
  +	i += nlength + 1;
  +    }
  +    memcpy(&val[i], &tmp[k], 22 - k);
  +    val[i + 22 - k] = '\0';
   }
   
   #else
   
  -void
  -proxy_hash(const char *it, char *val,int ndepth,int nlength)
  +void proxy_hash(const char *it, char *val, int ndepth, int nlength)
   {
       AP_MD5_CTX context;
       unsigned char digest[16];
       char tmp[22];
       int i, k, d;
       unsigned int x;
  -    static const char table[64]=
  -"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
  +    static const char table[64] =
  +    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
   
       MD5Init(&context);
  -    MD5Update(&context, (const unsigned char *)it, strlen(it));
  +    MD5Update(&context, (const unsigned char *) it, strlen(it));
       MD5Final(digest, &context);
   
   /* encode 128 bits as 22 characters, using a modified uuencoding */
   /* the encoding is 3 bytes -> 4 characters
    * i.e. 128 bits is 5 x 3 bytes + 1 byte -> 5 * 4 characters + 2 characters
    */
  -    for (i=0, k=0; i < 15; i += 3)
  -    {
  -	x = (digest[i] << 16) | (digest[i+1] << 8) | digest[i+2];
  +    for (i = 0, k = 0; i < 15; i += 3) {
  +	x = (digest[i] << 16) | (digest[i + 1] << 8) | digest[i + 2];
   	tmp[k++] = table[x >> 18];
   	tmp[k++] = table[(x >> 12) & 0x3f];
   	tmp[k++] = table[(x >> 6) & 0x3f];
  @@ -656,19 +676,18 @@
       }
   /* one byte left */
       x = digest[15];
  -    tmp[k++] = table[x >> 2];  /* use up 6 bits */
  +    tmp[k++] = table[x >> 2];	/* use up 6 bits */
       tmp[k++] = table[(x << 4) & 0x3f];
       /* now split into directory levels */
   
  -    for(i=k=d=0 ; d < ndepth ; ++d)
  -	{
  -	strncpy(&val[i],&tmp[k],nlength);
  -	k+=nlength;
  -	val[i+nlength]='/';
  -	i+=nlength+1;
  -	}
  -    memcpy(&val[i],&tmp[k],22-k);
  -    val[i+22-k]='\0';
  +    for (i = k = d = 0; d < ndepth; ++d) {
  +	strncpy(&val[i], &tmp[k], nlength);
  +	k += nlength;
  +	val[i + nlength] = '/';
  +	i += nlength + 1;
  +    }
  +    memcpy(&val[i], &tmp[k], 22 - k);
  +    val[i + 22 - k] = '\0';
   }
   
   #endif /* WIN32 */
  @@ -676,61 +695,62 @@
   /*
    * Converts 8 hex digits to a time integer
    */
  -int
  -proxy_hex2sec(const char *x)
  +int proxy_hex2sec(const char *x)
   {
       int i, ch;
       unsigned int j;
   
  -    for (i=0, j=0; i < 8; i++)
  -    {
  +    for (i = 0, j = 0; i < 8; i++) {
   	ch = x[i];
   	j <<= 4;
  -	if (isdigit(ch)) j |= ch - '0';
  -	else if (isupper(ch)) j |= ch - ('A' - 10);
  -	else j |= ch - ('a' - 10);
  +	if (isdigit(ch))
  +	    j |= ch - '0';
  +	else if (isupper(ch))
  +	    j |= ch - ('A' - 10);
  +	else
  +	    j |= ch - ('a' - 10);
       }
  -    if (j == 0xffffffff) return -1;  /* so that it works with 8-byte ints */
  -    else return j;
  +    if (j == 0xffffffff)
  +	return -1;		/* so that it works with 8-byte ints */
  +    else
  +	return j;
   }
   
   /*
    * Converts a time integer to 8 hex digits
    */
  -void
  -proxy_sec2hex(int t, char *y)
  +void proxy_sec2hex(int t, char *y)
   {
       int i, ch;
  -    unsigned int j=t;
  +    unsigned int j = t;
   
  -    for (i=7; i >= 0; i--)
  -    {
  +    for (i = 7; i >= 0; i--) {
   	ch = j & 0xF;
   	j >>= 4;
  -	if (ch >= 10) y[i] = ch + ('A' - 10);
  -	else y[i] = ch + '0';
  +	if (ch >= 10)
  +	    y[i] = ch + ('A' - 10);
  +	else
  +	    y[i] = ch + '0';
       }
       y[8] = '\0';
   }
   
  -void
  -proxy_log_uerror(const char *routine, const char *file, const char *err,
  -	   server_rec *s)
  +void proxy_log_uerror(const char *routine, const char *file, const char *err,
  +		      server_rec *s)
   {
       char *p, *q;
   
       q = get_time();
       p = strerror(errno);
   
  -    if (err != NULL)
  -    {
  +    if (err != NULL) {
   	fprintf(s->error_log, "[%s] %s\n", q, err);
   	if (file != NULL)
   	    fprintf(s->error_log, "- %s: %s: %s\n", routine, file, p);
   	else
   	    fprintf(s->error_log, "- %s: %s\n", routine, p);
  -    } else
  -    {
  +    }
  +    else {
   	if (file != NULL)
   	    fprintf(s->error_log, "[%s] %s: %s: %s\n", q, routine, file, p);
   	else
  @@ -741,18 +761,17 @@
   }
   
   BUFF *
  -proxy_cache_error(struct cache_req *c)
  +     proxy_cache_error(struct cache_req *c)
   {
       proxy_log_uerror("write", c->tempfile, "proxy: error writing to cache file",
  -        c->req->server);
  +		     c->req->server);
       pclosef(c->req->pool, c->fp->fd);
  -    c->fp = NULL; 
  +    c->fp = NULL;
       unlink(c->tempfile);
       return NULL;
   }
   
  -int
  -proxyerror(request_rec *r, const char *message)
  +int proxyerror(request_rec *r, const char *message)
   {
       r->status = SERVER_ERROR;
       r->status_line = "500 Proxy Error";
  @@ -775,34 +794,33 @@
    * This routine returns its own error message
    */
   const char *
  -proxy_host2addr(const char *host, struct hostent *reqhp)
  +     proxy_host2addr(const char *host, struct hostent *reqhp)
   {
       int i;
       struct hostent *hp;
       static APACHE_TLS struct hostent hpbuf;
       static APACHE_TLS u_long ipaddr;
  -    static APACHE_TLS char* charpbuf[2];
  +    static APACHE_TLS char *charpbuf[2];
   
  -    for (i=0; host[i] != '\0'; i++)
  +    for (i = 0; host[i] != '\0'; i++)
   	if (!isdigit(host[i]) && host[i] != '.')
   	    break;
   
  -    if (host[i] != '\0')
  -    {
  +    if (host[i] != '\0') {
   	hp = gethostbyname(host);
   	if (hp == NULL)
   	    return "Host not found";
  -    } else
  -    {
  +    }
  +    else {
   	ipaddr = ap_inet_addr(host);
  -	hp = gethostbyaddr((char *)&ipaddr, sizeof(u_long), AF_INET);
  +	hp = gethostbyaddr((char *) &ipaddr, sizeof(u_long), AF_INET);
   	if (hp == NULL) {
   	    memset(&hpbuf, 0, sizeof(hpbuf));
   	    hpbuf.h_name = 0;
   	    hpbuf.h_addrtype = AF_INET;
   	    hpbuf.h_length = sizeof(u_long);
   	    hpbuf.h_addr_list = charpbuf;
  -	    hpbuf.h_addr_list[0] = (char*)&ipaddr;
  +	    hpbuf.h_addr_list[0] = (char *) &ipaddr;
   	    hpbuf.h_addr_list[1] = 0;
   	    hp = &hpbuf;
   	}
  @@ -812,7 +830,7 @@
   }
   
   static char *
  -proxy_get_host_of_request(request_rec *r)
  +     proxy_get_host_of_request(request_rec *r)
   {
       char *url, *user = NULL, *password = NULL, *err, *host;
       int port = -1;
  @@ -821,11 +839,11 @@
   	return r->hostname;
   
       /* Set url to the first char after "scheme://" */
  -    if ((url = strchr(r->uri,':')) == NULL
  +    if ((url = strchr(r->uri, ':')) == NULL
   	|| url[1] != '/' || url[2] != '/')
   	return NULL;
   
  -    url = pstrdup(r->pool, &url[1]); /* make it point to "//", which is what proxy_canon_netloc expects */
  +    url = pstrdup(r->pool, &url[1]);	/* make it point to "//", which is what proxy_canon_netloc expects */
   
       err = proxy_canon_netloc(r->pool, &url, &user, &password, &host, &port);
   
  @@ -834,16 +852,15 @@
   
       r->hostname = host;
   
  -    return host;        /* ought to return the port, too */
  +    return host;		/* ought to return the port, too */
   }
   
  -/* Return TRUE if addr represents an IP address (or an IP network address)*/
  -int
  -proxy_is_ipaddr(struct dirconn_entry *This)
  +/* Return TRUE if addr represents an IP address (or an IP network address) */
  +int proxy_is_ipaddr(struct dirconn_entry *This)
   {
       const char *addr = This->name;
       unsigned long ip_addr[4];
  -    int i,quads;
  +    int i, quads;
       unsigned long bits;
   
       /* if the address is given with an explicit netmask, use that */
  @@ -851,68 +868,65 @@
       /* "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)*/
  -	/* addr and mask were set by proxy_readmask() */
  -	/*return 1;*/
  +    /*if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0) */
  +    /* addr and mask were set by proxy_readmask() */
  +    /*return 1; */
   
       /* Parse IP addr manually, optionally allowing */
       /* abbreviated net addresses like 192.168. */
   
   /*    quads = sscanf(what, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1],
  -				  &ip_addr[2], &ip_addr[3]);
  -    commented out: use of strtok() allows arbitrary base, like in:
  -    139.25.113.10 == 0x8b.0x19.0x71.0x0a
  -    (yes, inet_addr() can parse that, too!)
  +   &ip_addr[2], &ip_addr[3]);
  +   commented out: use of strtok() allows arbitrary base, like in:
  +   139.25.113.10 == 0x8b.0x19.0x71.0x0a
  +   (yes, inet_addr() can parse that, too!)
    */
   
       /* Iterate over up to 4 (dotted) quads. */
  -    for (quads=0; quads<4 && *addr != '\0'; ++quads)
  -    {
  +    for (quads = 0; quads < 4 && *addr != '\0'; ++quads) {
   	char *tmp;
   
  -	if (*addr == '/' && quads > 0)  /* netmask starts here. */
  +	if (*addr == '/' && quads > 0)	/* netmask starts here. */
   	    break;
   
   	if (!isdigit(*addr))
  -	    return 0;       /* no digit at start of quad */
  +	    return 0;		/* no digit at start of quad */
   
   	ip_addr[quads] = strtoul(addr, &tmp, 0);
   
  -	if (tmp == addr)    /* expected a digit, found something else */
  +	if (tmp == addr)	/* expected a digit, found something else */
   	    return 0;
   
   	addr = tmp;
   
   	if (*addr == '.' && quads != 3)
  -	    ++addr;            /* after the 4th quad, a dot would be illegal */
  +	    ++addr;		/* after the 4th quad, a dot would be illegal */
       }
   
  -    for (This->addr.s_addr = 0, i=0; i<quads; ++i)
  -	This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8*i));
  +    for (This->addr.s_addr = 0, i = 0; i < quads; ++i)
  +	This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
   
  -    if (addr[0] == '/' && isdigit(addr[1]))    /* net mask follows: */
  -    {
  +    if (addr[0] == '/' && isdigit(addr[1])) {	/* net mask follows: */
   	char *tmp;
   
   	++addr;
   
   	bits = strtoul(addr, &tmp, 0);
   
  -	if (tmp == addr)    /* expected a digit, found something else */
  +	if (tmp == addr)	/* expected a digit, found something else */
   	    return 0;
   
   	addr = tmp;
   
  -	if (bits > 32)    /* netmask must be between 0 and 32 */
  +	if (bits > 32)		/* netmask must be between 0 and 32 */
   	    return 0;
   
       }
  -    else
  -    {
  +    else {
   	/* Determine (i.e., "guess") netmask by counting the */
   	/* number of trailing .0's; reduce #quads appropriately */
   	/* (so that 192.168.0.0 is equivalent to 192.168.)        */
  -	while (quads > 0 && ip_addr[quads-1] == 0)
  +	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)"; */
  @@ -920,36 +934,33 @@
   	    return 0;
   
   	/* every zero-byte counts as 8 zero-bits */
  -	bits = 8*quads;
  +	bits = 8 * quads;
   
  -	if (bits != 32)  /* no warning for fully qualified IP address */
  -	    fprintf(stderr,"Warning: NetMask not supplied with IP-Addr; guessing: %s/%ld\n",
  -			   inet_ntoa(This->addr), bits);
  +	if (bits != 32)		/* no warning for fully qualified IP address */
  +	    fprintf(stderr, "Warning: NetMask not supplied with IP-Addr; guessing: %s/%ld\n",
  +		    inet_ntoa(This->addr), bits);
       }
   
       This->mask.s_addr = htonl(INADDR_NONE << (32 - bits));
   
  -    if (*addr == '\0' && (This->addr.s_addr & ~This->mask.s_addr) != 0)
  -    {
  -	fprintf(stderr,"Warning: NetMask and IP-Addr disagree in %s/%ld\n",
  -		       inet_ntoa(This->addr), bits);
  +    if (*addr == '\0' && (This->addr.s_addr & ~This->mask.s_addr) != 0) {
  +	fprintf(stderr, "Warning: NetMask and IP-Addr disagree in %s/%ld\n",
  +		inet_ntoa(This->addr), bits);
   	This->addr.s_addr &= This->mask.s_addr;
  -	fprintf(stderr,"         Set to %s/%ld\n",
  -		       inet_ntoa(This->addr), bits);
  +	fprintf(stderr, "         Set to %s/%ld\n",
  +		inet_ntoa(This->addr), bits);
       }
   
  -    if (*addr == '\0')
  -    {
  +    if (*addr == '\0') {
   	This->matcher = proxy_match_ipaddr;
   	return 1;
       }
       else
  -    return (*addr == '\0');   /* okay iff we've parsed the whole string */
  +	return (*addr == '\0');	/* okay iff we've parsed the whole string */
   }
   
  -/* Return TRUE if addr represents an IP address (or an IP network address)*/
  -static int
  -proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
  +/* Return TRUE if addr represents an IP address (or an IP network address) */
  +static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
   {
       int i;
       int ip_addr[4];
  @@ -959,43 +970,38 @@
       const char *found;
       const char *host = proxy_get_host_of_request(r);
   
  -    memset (&addr, '\0', sizeof addr);
  -    memset (ip_addr, '\0', sizeof ip_addr);
  +    memset(&addr, '\0', sizeof addr);
  +    memset(ip_addr, '\0', sizeof ip_addr);
   
  -    if ( 4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3]))
  -    {
  -	for (addr.s_addr = 0, i=0; i<4; ++i)
  -	    addr.s_addr |= htonl(ip_addr[i] << (24 - 8*i));
  +    if (4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3])) {
  +	for (addr.s_addr = 0, i = 0; i < 4; ++i)
  +	    addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
   
  -	if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr))
  -	{
  +	if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr)) {
   #if DEBUGGING
  -	    fprintf(stderr,"1)IP-Match: %s[%s] <-> ", host, inet_ntoa(addr));
  -	    fprintf(stderr,"%s/", inet_ntoa(This->addr));
  -	    fprintf(stderr,"%s\n", inet_ntoa(This->mask));
  +	    fprintf(stderr, "1)IP-Match: %s[%s] <-> ", host, inet_ntoa(addr));
  +	    fprintf(stderr, "%s/", inet_ntoa(This->addr));
  +	    fprintf(stderr, "%s\n", inet_ntoa(This->mask));
   #endif
   	    return 1;
   	}
   #if DEBUGGING
  -	else
  -	{
  -	    fprintf(stderr,"1)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(addr));
  -	    fprintf(stderr,"%s/", inet_ntoa(This->addr));
  -	    fprintf(stderr,"%s\n", inet_ntoa(This->mask));
  +	else {
  +	    fprintf(stderr, "1)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(addr));
  +	    fprintf(stderr, "%s/", inet_ntoa(This->addr));
  +	    fprintf(stderr, "%s\n", inet_ntoa(This->mask));
   	}
   #endif
       }
  -    else
  -    {
  +    else {
   	struct hostent the_host;
   
  -	memset (&the_host, '\0', sizeof the_host);
  +	memset(&the_host, '\0', sizeof the_host);
   	found = proxy_host2addr(host, &the_host);
   
  -	if ( found != NULL )
  -	{
  +	if (found != NULL) {
   #if DEBUGGING
  -	    fprintf(stderr,"2)IP-NoMatch: hostname=%s msg=%s\n", host, found);
  +	    fprintf(stderr, "2)IP-NoMatch: hostname=%s msg=%s\n", host, found);
   #endif
   	    return 0;
   	}
  @@ -1006,37 +1012,33 @@
   	    found = host;
   
   	/* Try to deal with multiple IP addr's for a host */
  -	for (ip_listptr=the_host.h_addr_list; *ip_listptr; ++ip_listptr)
  -	{
  +	for (ip_listptr = the_host.h_addr_list; *ip_listptr; ++ip_listptr) {
   	    ip_list = (struct in_addr *) *ip_listptr;
  -	    if (This->addr.s_addr == (ip_list->s_addr & This->mask.s_addr))
  -	    {
  +	    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));
  -		fprintf(stderr,"%s/", inet_ntoa(This->addr));
  -		fprintf(stderr,"%s\n", inet_ntoa(This->mask));
  +		fprintf(stderr, "3)IP-Match: %s[%s] <-> ", found, inet_ntoa(*ip_list));
  +		fprintf(stderr, "%s/", inet_ntoa(This->addr));
  +		fprintf(stderr, "%s\n", inet_ntoa(This->mask));
   #endif
   		return 1;
   	    }
   #if DEBUGGING
  -	    else
  -	    {
  -		fprintf(stderr,"3)IP-NoMatch: %s[%s] <-> ", found, inet_ntoa(*ip_list));
  -		fprintf(stderr,"%s/", inet_ntoa(This->addr));
  -		fprintf(stderr,"%s\n", inet_ntoa(This->mask));
  +	    else {
  +		fprintf(stderr, "3)IP-NoMatch: %s[%s] <-> ", found, inet_ntoa(*ip_list));
  +		fprintf(stderr, "%s/", inet_ntoa(This->addr));
  +		fprintf(stderr, "%s\n", inet_ntoa(This->mask));
   	    }
   #endif
   	}
       }
   
       /* Use net math to determine if a host lies in a subnet */
  -    /*return This->addr.s_addr == (r->connection->remote_addr.sin_addr.s_addr & This->mask.s_addr);*/
  +    /*return This->addr.s_addr == (r->connection->remote_addr.sin_addr.s_addr & This->mask.s_addr); */
       return 0;
   }
   
   /* Return TRUE if addr represents a domain name */
  -int
  -proxy_is_domainname(struct dirconn_entry *This)
  +int proxy_is_domainname(struct dirconn_entry *This)
   {
       char *addr = This->name;
       int i;
  @@ -1046,12 +1048,10 @@
   	return 0;
   
       /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
  -    for (i=0; isalnum(addr[i]) || addr[i]=='-' || addr[i]=='.'; ++i)
  -	;
  +    for (i = 0; isalnum(addr[i]) || addr[i] == '-' || addr[i] == '.'; ++i);
   
  -    if (addr[i] == ':')
  -    {
  -	fprintf(stderr,"@@@@ handle optional port in proxy_is_domainname()\n");
  +    if (addr[i] == ':') {
  +	fprintf(stderr, "@@@@ handle optional port in proxy_is_domainname()\n");
   	/* @@@@ handle optional port */
       }
   
  @@ -1059,7 +1059,7 @@
   	return 0;
   
       /* Strip trailing dots */
  -    for (i=strlen(addr)-1; i>0 && addr[i] == '.'; --i)
  +    for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i)
   	addr[i] = '\0';
   
       This->matcher = proxy_match_domainname;
  @@ -1067,30 +1067,28 @@
   }
   
   /* Return TRUE if host "host" is in domain "domain" */
  -static int
  -proxy_match_domainname(struct dirconn_entry *This, request_rec *r)
  +static int proxy_match_domainname(struct dirconn_entry *This, request_rec *r)
   {
       const char *host = proxy_get_host_of_request(r);
  -    int d_len=strlen(This->name), h_len;
  +    int d_len = strlen(This->name), h_len;
   
  -    if (host == NULL)   /* some error was logged already */
  +    if (host == NULL)		/* some error was logged already */
   	return 0;
   
       h_len = strlen(host);
   
       /* @@@ do this within the setup? */
       /* Ignore trailing dots in domain comparison: */
  -    while (d_len > 0 && This->name[d_len-1] == '.')
  +    while (d_len > 0 && This->name[d_len - 1] == '.')
   	--d_len;
  -    while (h_len > 0 && host[h_len-1] == '.')
  +    while (h_len > 0 && host[h_len - 1] == '.')
   	--h_len;
       return h_len > d_len
  -	&& strncasecmp(&host[h_len-d_len], This->name, d_len) == 0;
  +	&& strncasecmp(&host[h_len - d_len], This->name, d_len) == 0;
   }
   
   /* Return TRUE if addr represents a host name */
  -int
  -proxy_is_hostname(struct dirconn_entry *This)
  +int proxy_is_hostname(struct dirconn_entry *This)
   {
       char *addr = This->name;
       int i;
  @@ -1100,12 +1098,10 @@
   	return 0;
   
       /* rfc1035 says DNS names must consist of "[-a-zA-Z0-9]" and '.' */
  -    for (i=0; isalnum(addr[i]) || addr[i]=='-' || addr[i]=='.'; ++i)
  -	;
  +    for (i = 0; isalnum(addr[i]) || addr[i] == '-' || addr[i] == '.'; ++i);
   
  -    if (addr[i] == ':')
  -    {
  -	fprintf(stderr,"@@@@ handle optional port in proxy_is_hostname()\n");
  +    if (addr[i] == ':') {
  +	fprintf(stderr, "@@@@ handle optional port in proxy_is_hostname()\n");
   	/* @@@@ handle optional port */
       }
   
  @@ -1113,7 +1109,7 @@
   	return 0;
   
       /* Strip trailing dots */
  -    for (i=strlen(addr)-1; i>0 && addr[i] == '.'; --i)
  +    for (i = strlen(addr) - 1; i > 0 && addr[i] == '.'; --i)
   	addr[i] = '\0';
   
       This->matcher = proxy_match_hostname;
  @@ -1121,59 +1117,55 @@
   }
   
   /* Return TRUE if host "host" is equal to host2 "host2" */
  -static int
  -proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
  +static int proxy_match_hostname(struct dirconn_entry *This, request_rec *r)
   {
       char *host = This->name;
       char *host2 = proxy_get_host_of_request(r);
  -    int h2_len=strlen(host2);
  -    int h1_len=strlen(host);
  +    int h2_len = strlen(host2);
  +    int h1_len = strlen(host);
   
   #if 0
       unsigned long *ip_list;
   
       /* Try to deal with multiple IP addr's for a host */
       for (ip_list = *This->hostlist.h_addr_list; *ip_list != 0UL; ++ip_list)
  -	if (*ip_list == ?????????????)
  +	if (*ip_list == ? ? ? ? ? ? ? ? ? ? ? ? ?)
   	    return 1;
   #endif
   
       /* Ignore trailing dots in host2 comparison: */
  -    while (h2_len > 0 && host2[h2_len-1] == '.')
  +    while (h2_len > 0 && host2[h2_len - 1] == '.')
   	--h2_len;
  -    while (h1_len > 0 && host[h1_len-1] == '.')
  +    while (h1_len > 0 && host[h1_len - 1] == '.')
   	--h1_len;
       return h1_len == h2_len
   	&& strncasecmp(host, host2, h1_len) == 0;
   }
   
   /* Return TRUE if addr is to be matched as a word */
  -int
  -proxy_is_word(struct dirconn_entry *This)
  +int proxy_is_word(struct dirconn_entry *This)
   {
       This->matcher = proxy_match_word;
       return 1;
   }
   
   /* Return TRUE if string "str2" occurs literally in "str1" */
  -static int
  -proxy_match_word(struct dirconn_entry *This, request_rec *r)
  +static int proxy_match_word(struct dirconn_entry *This, request_rec *r)
   {
       char *host = proxy_get_host_of_request(r);
  -    return host != NULL  &&  strstr(host, This->name) != NULL;
  +    return host != NULL && strstr(host, This->name) != NULL;
   }
   
  -int
  -proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r)
  +int proxy_doconnect(int sock, struct sockaddr_in *addr, request_rec *r)
   {
       int i;
   
       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));
   #ifdef WIN32
  -        if(i == SOCKET_ERROR)
  -            errno = WSAGetLastError() - WSABASEERR;
  +	if (i == SOCKET_ERROR)
  +	    errno = WSAGetLastError() - WSABASEERR;
   #endif /* WIN32 */
       } while (i == -1 && errno == EINTR);
       if (i == -1) {
  
  
  
  1.1                  apachen/src/modules/proxy/.indent.pro
  
  Index: .indent.pro
  ===================================================================
  -i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1
  -TBUFF
  -TFILE
  -TTRANS
  -TUINT4
  -T_trans
  -Tallow_options_t
  -Tapache_sfio
  -Tarray_header
  -Tbool_int
  -Tbuf_area
  -Tbuff_struct
  -Tbuffy
  -Tcmd_how
  -Tcmd_parms
  -Tcommand_rec
  -Tcommand_struct
  -Tconn_rec
  -Tcore_dir_config
  -Tcore_server_config
  -Tdir_maker_func
  -Tevent
  -Tglobals_s
  -Thandler_func
  -Thandler_rec
  -Tjoblist_s
  -Tlisten_rec
  -Tmerger_func
  -Tmode_t
  -Tmodule
  -Tmodule_struct
  -Tmutex
  -Tn_long
  -Tother_child_rec
  -Toverrides_t
  -Tparent_score
  -Tpid_t
  -Tpiped_log
  -Tpool
  -Trequest_rec
  -Trequire_line
  -Trlim_t
  -Tscoreboard
  -Tsemaphore
  -Tserver_addr_rec
  -Tserver_rec
  -Tserver_rec_chain
  -Tshort_score
  -Ttable
  -Ttable_entry
  -Tthread
  -Tu_wide_int
  -Tvtime_t
  -Twide_int
  -Tproxy_server_conf
  
  
  

Mime
View raw message