/** * Look at the request to see if Caucho should handle it. */ static int cse_dispatch(request_rec *r) { config_t *config = cse_get_module_config(r); const char *host = ap_get_server_name(r); const char *uri = r->uri; unsigned int now = r->request_time; LOG(("CONF: %p\n", config)); if (config == NULL) return DECLINED; /* cse_update_config(config, r->request_time); */ if (config->enable_caucho_status && strstr(uri, "/caucho-status")) { r->handler = "caucho-status"; return OK; } /* Check for exact virtual host match */ if (cse_match_request(config, host, ap_get_server_port(r), uri, 0, now) || r->handler && ! strcmp(r->handler, "caucho-request")) { r->handler = "caucho-request"; LOG(("[%d] match %s:%s\n", getpid(), host ? host : "null", uri)); return OK; } LOG(("[%d] mismatch %s:%s\n", getpid(), host ? host : "null", uri)); return DECLINED; }
/** * Strip the ;jsessionid */ static int cse_strip(request_rec *r) { config_t *config = cse_get_module_config(r); const char *uri = r->uri; if (config == NULL || ! uri) return DECLINED; if (config->session_url_prefix) { char buffer[8192]; char *new_uri; new_uri = strstr(uri, config->session_url_prefix); if (new_uri) { *new_uri = 0; /* Strip session encoding from static files. */ if (r->filename) { char *url_rewrite = strstr(r->filename, config->session_url_prefix); if (url_rewrite) { *url_rewrite = 0; /* if (stat(r->filename, &r->finfo) < 0) r->finfo.st_mode = 0; */ } } if (r->args) { sprintf(buffer, "%s?%s", r->uri, r->args); apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, buffer, r)); } else { apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, r->uri, r)); } return HTTP_MOVED_PERMANENTLY; } } return DECLINED; }
/** * Look at the request to see if Resin should handle it. */ static int cse_dispatch(request_rec *r) { config_t *config = cse_get_module_config(r); const char *host_name = ap_get_server_name(r); int port = ap_get_server_port(r); const char *uri = r->uri; resin_host_t *host; unsigned int now; int len; if (config == NULL || ! uri) return DECLINED; now = time(0); LOG(("%s:%d:cse_dispatch(): [%d] host %s\n", __FILE__, __LINE__, getpid(), host_name ? host_name : "null")); len = strlen(uri); /* move back below host */ if (config->enable_caucho_status && len >= sizeof("/caucho-status") - 1 && ! strcmp(uri + len - sizeof("/caucho-status") + 1, "/caucho-status")) { r->handler = "caucho-status"; return caucho_status(r); } /* Check for exact virtual host match */ host = cse_match_request(config, host_name, port, uri, 0, now); if (host || (r->handler && ! strcmp(r->handler, "caucho-request"))) { LOG(("%s:%d:cse_dispatch(): [%d] match %s:%s\n", __FILE__, __LINE__, getpid(), host_name ? host_name : "null", uri)); return caucho_request(r, config, host, now); } else if (r->handler && ! strcmp(r->handler, "caucho-status")) { return caucho_status(r); } if (config->session_url_prefix) { return cse_strip(r); } return DECLINED; }
/** * 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; }
/** * Handle a request. */ static int caucho_request(request_rec *r) { config_t *config = cse_get_module_config(r); resin_host_t *host = 0; stream_t s; int retval; int keepalive = 0; int reuse; int session_index; int backup_index; char *ip; time_t now = r->request_time; char *session_id = 0; if (! config) return HTTP_SERVICE_UNAVAILABLE; if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK))) return retval; /* ap_soft_timeout("servlet request", r); */ if (r->request_config && ! *config->alt_session_url_prefix && ((session_id = ap_get_module_config(r->request_config, &caucho_module)) || r->prev && (session_id = ap_get_module_config(r->prev->request_config, &caucho_module)))) { /* *session_id = *config->session_url_prefix; */ } session_index = get_session_index(config, r, &backup_index); ip = r->connection->remote_ip; if (host) { } else if (config->manual_host) host = config->manual_host; else { host = cse_match_host(config, ap_get_server_name(r), ap_get_server_port(r), now); } if (! host || ! cse_open_connection(&s, &host->cluster, session_index, backup_index, now, r->pool)) { return HTTP_SERVICE_UNAVAILABLE; } reuse = write_request(&s, r, config, &host->cluster, &keepalive, session_index, backup_index, ip, session_id); /* ap_kill_timeout(r); */ ap_rflush(r); if (reuse == HMUX_QUIT) cse_recycle(&s, now); else cse_close(&s, "no reuse"); if (reuse == HTTP_SERVICE_UNAVAILABLE) return reuse; else return OK; }
/** * Look at the request to see if Caucho should handle it. */ static int cse_clean_jsessionid(request_rec *r) { config_t *config = cse_get_module_config(r); char *uri = (char *) r->uri; char *new_uri; if (config == NULL) return DECLINED; /* cse_update_config(config, r->request_time); */ if (*config->alt_session_url_prefix) { if (! strncmp(uri + 1, config->alt_session_url_prefix, sizeof(config->alt_session_url_prefix))) { char *p = strchr(uri + 1, '/'); if (r->request_config) ap_set_module_config(r->request_config, &caucho_module, uri); r->uri = p; /* strip session encoding from file */ if (r->filename) { char *prefix = strstr(r->filename, config->alt_session_url_prefix); p = prefix ? strchr(prefix, '/') : 0; if (prefix && p) { memcpy(prefix, p, strlen(p)); /* restat the new filename */ if (stat(r->filename, &r->finfo) < 0) r->finfo.st_mode = 0; } } } } else { new_uri = strstr(uri, config->session_url_prefix); if (new_uri) { if (r->request_config) { ap_set_module_config(r->request_config, &caucho_module, new_uri); } *new_uri = 0; /* Strip session encoding from static files. */ if (r->filename) { char *url_rewrite = strstr(r->filename, config->session_url_prefix); if (url_rewrite) { *url_rewrite = 0; if (stat(r->filename, &r->finfo) < 0) { r->finfo.st_mode = 0; } } } } } return DECLINED; }
/** * 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; }