static void
caucho_host_status(request_rec *r, config_t *config, resin_host_t *host)
{
  web_app_t *app;
  location_t *loc;
  unsigned int now = time(0);
  
  /* check updates as appropriate */
  cse_match_host(config, host->name, host->port, now);

  if (host->canonical == host)
    ap_rprintf(r, "<h2>");
  else
    ap_rprintf(r, "<h3>");

  if (! host->has_data)
    ap_rprintf(r, "Unconfigured ");
  
  if (host->canonical != host)
    ap_rprintf(r, "Alias ");
  
  if (! *host->name)
    ap_rprintf(r, "Default Virtual Host");
  else if (host->port)
    ap_rprintf(r, "Virtual Host: %s:%d", host->name, host->port);
  else
    ap_rprintf(r, "Virtual Host: %s", host->name);

  if (host->canonical == host) {
  }
  else if (! host->canonical)
    ap_rprintf(r, " -> <font color='red'>null</font>");
  else if (host->canonical->port)
    ap_rprintf(r, " -> %s:%d", host->canonical->name, host->canonical->port);
  else if (! host->canonical->name[0])
    ap_rprintf(r, " -> default");
  else
    ap_rprintf(r, " -> %s", host->canonical->name);
  
  if (host->canonical == host)
    ap_rprintf(r, "</h2>");
  else
    ap_rprintf(r, "</h3>");

  if (host->error_message[0])
    ap_rprintf(r, "<h3 color='red'>Error: %s</h3>\n", host->error_message);

  ap_rprintf(r, "<p style='margin-left:2em'>");

  if (host->config_source[0]) {
    ap_rprintf(r, "<b>Source:</b> %s<br />\n",
	       host->config_source);
  }
  
  ap_rprintf(r, "<b>Last-Update:</b> %s</p><br />\n",
	     ctime(&host->last_update_time));
  ap_rprintf(r, "</p>\n");

  if (host->canonical == host) {
    jvm_status(&host->cluster, r);

    ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r);
    ap_rputs("<tr><th width=\"50%\">web-app\n", r);
    ap_rputs("    <th>url-pattern\n", r);

    app = host->applications;
    
    for (; app; app = app->next) {
      if (! app->has_data) {
	ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>unconfigured</tr>\n", 
		   *app->context_path ? app->context_path : "/");
      }
      
      for (loc = app->locations; loc; loc = loc->next) {
	if (! strcasecmp(loc->prefix, "/META-INF") ||
	    ! strcasecmp(loc->prefix, "/WEB-INF"))
	  continue;
	
	ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s%s</tr>\n", 
		   *app->context_path ? app->context_path : "/",
		   loc->prefix,
		   ! loc->is_exact && ! loc->suffix ? "/*" : 
		   loc->suffix && loc->prefix[0] ? "/" : "",
		   loc->suffix ? "*" : "",
		   loc->suffix ? loc->suffix : "",
		   loc->ignore ? " (ignore)" : "");
      }
    }
    ap_rputs("</table></center>\n", r);
  }
}
/**
 * Print a summary of the configuration so users can understand what's
 * going on.  Ping the server to check that it's up.
 */
static int
caucho_status(request_rec *r)
{
  config_t *config;
  resin_host_t *host;
  time_t now = time(0);
 
  if (! r->handler || strcmp(r->handler, "caucho-status"))
    return DECLINED;

  config = cse_get_module_config(r);

  if (! config)
    return DECLINED;
  
  r->content_type = "text/html";
  if (r->header_only)
    return OK;

  ap_rputs("<html><title>Status : Caucho Servlet Engine</title>\n", r);
  ap_rputs("<body bgcolor=white>\n", r);
  ap_rputs("<h1>Status : Caucho Servlet Engine</h1>\n", r);

  if (! config)
    return OK;

  if (config->error)
    ap_rprintf(r, "<h2 color='red'>Error : %s</h2>\n", config->error);

  ap_rprintf(r, "<table border='0'>");
  ap_rprintf(r, "<tr><td><b>Start Time</b></td><td>%s</td></tr>\n",
	     ctime(&config->start_time));
  ap_rprintf(r, "<tr><td><b>Now</b></td><td>%s</td></tr>\n",
	     ctime(&now));
  ap_rprintf(r, "<tr><td><b>Session Cookie</b></td><td>'%s'</td></tr>\n",
	     config->session_cookie);
  ap_rprintf(r, "<tr><td><b>Session URL</b></td><td>'%s'</td></tr>\n",
	     config->session_url_prefix);
  ap_rprintf(r, "<tr><td><b>Config Check Interval</b></b></td><td>%ds</td></tr>\n",
	     config->update_timeout);
  if (config->config_path && config->config_path[0]) {
    ap_rprintf(r, "<tr><td><b>Config Cache File</b></td><td>%s</td></tr>\n",
	       config->config_path);
  }
  
  ap_rprintf(r, "</table>");
  
  ap_rprintf(r, "<h2>Configuration Cluster</h2>\n");
  jvm_status(&config->config_cluster, r);
  
  host = config ? config->hosts : 0;
  for (; host; host = host->next) {
    if (host != host->canonical) {
      continue;
    }

    caucho_host_status(r, config, host);
  }

  if (config->manual_host)
    caucho_host_status(r, config, config->manual_host);

  ap_rputs("<hr>", r);
  ap_rprintf(r, "<em>%s<em>", VERSION);
  ap_rputs("</body></html>\n", r);

  return OK;
}
/**
 * Print a summary of the configuration so users can understand what's
 * going on.  Ping the server to check that it's up.
 */
static int
caucho_status(request_rec *r)
{
  resin_host_t *host;
  web_app_t *app;
  location_t *loc;
  unsigned int now = r->request_time;
  config_t *config = cse_get_module_config(r);
 
  r->content_type = "text/html";
  /* ap_soft_timeout("caucho status", r); */
  if (r->header_only) {
    /* ap_kill_timeout(r); */

    return OK;
  }

  ap_send_http_header(r);

  ap_rputs("<html><title>Status : Caucho Servlet Engine</title>\n", r);
  ap_rputs("<body bgcolor=white>\n", r);
  ap_rputs("<h1>Status : Caucho Servlet Engine</h1>\n", r);

  if (config->error) {
    char buf[BUF_LENGTH];
    escape_html(buf, config->error);
    ap_rprintf(r, "<h2 color='red'>Error : %s</h2>\n", buf);
  }
  
  ap_rprintf(r, "<h2>Configuration Cluster</h2>\n");
  jvm_status(&config->config_cluster, r);
  
  host = config ? config->hosts : 0;
  for (; host; host = host->next) {
    if (host != host->canonical)
      continue;

    /* check updates as appropriate */
    cse_match_host(config, host->name, host->port, now);

    if (! *host->name)
      ap_rprintf(r, "<h2>Default Virtual Host</h2>\n");
    else if (host->port)
      ap_rprintf(r, "<h2>Virtual Host: %s:%d</h2>\n", host->name, host->port);
    else
      ap_rprintf(r, "<h2>Virtual Host: %s</h2>\n", host->name);
    
    jvm_status(&host->cluster, r);

    ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r);
    ap_rputs("<tr><th width=\"50%\">web-app\n", r);
    ap_rputs("    <th>url-pattern\n", r);

    app = host->applications;
    
    for (; app; app = app->next) {
      for (loc = app->locations; loc; loc = loc->next) {
	if (! strcasecmp(loc->prefix, "/META-INF") ||
	    ! strcasecmp(loc->prefix, "/WEB-INF"))
	  continue;
	
	ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s<td>%s%s%s%s%s</tr>\n", 
		   *app->context_path ? app->context_path : "/",
		   loc->prefix,
		   ! loc->is_exact && ! loc->suffix ? "/*" : 
		   loc->suffix && loc->prefix[0] ? "/" : "",
		   loc->suffix ? "*" : "",
		   loc->suffix ? loc->suffix : "",
		   loc->ignore ? " (ignore)" : "");
      }
    }
    ap_rputs("</table></center>\n", r);
  }

  ap_rputs("<hr>", r);
  ap_rprintf(r, "<em>%s<em>", VERSION);
  ap_rputs("</body></html>\n", r);
  
  /* ap_kill_timeout(r); */

  return OK;
}