⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_caucho.c

📁 resinweb服务器源文件
💻 C
📖 第 1 页 / 共 3 页
字号:
    case CSE_KEEPALIVE:      *keepalive = 1;      break;    case CSE_SEND_HEADER:      ap_send_http_header(r);      break;    case -1:      break;    case CSE_END:    case CSE_CLOSE:      cse_skip(s, len);      break;          default:      cse_skip(s, len);      break;    }  } while (code > 0 && code != CSE_END && code != CSE_CLOSE && code != ack);  return code;}/** * handles a client request */static intwrite_request(stream_t *s, request_rec *r, config_t *config, int *keepalive,              int session_index, int backup_index,              char *ip, char *session_id){  int len;  int code;  int write_length;  time_t new_time;  time_t start_time = r->request_time;  write_env(s, r, session_id);  write_headers(s, r);  write_added_headers(s, r);  /* read post data */  if (ap_should_client_block(r)) {    char buf[BUF_LENGTH];    int isFirst = 1;    while ((len = ap_get_client_block(r, buf, BUF_LENGTH)) > 0) {      /* ap_reset_timeout(r); */      cse_write_packet(s, CSE_DATA, buf, len);            if (! isFirst) {        code = send_data(s, r, CSE_ACK, keepalive);        if (code < 0 || code == CSE_END || code == CSE_CLOSE)          break;      }      isFirst = 0;    }  }  cse_write_packet(s, CSE_END, 0, 0);  code = send_data(s, r, CSE_END, keepalive);  if (code >= 0 || s->sent_data)    return code;    write_length = s->write_length;   if (cse_open_connection(s, config, session_index, backup_index,                          r->request_time, r->pool)) {    s->write_length = write_length;    LOG(("retry connection %d\n", s->socket));        return send_data(s, r, CSE_END, keepalive);  }  else {    LOG(("retry fail\n"));       return HTTP_SERVICE_UNAVAILABLE;  }}#ifdef WIN32int random() { return 0; }#endif/** * Handle a request. */static intcaucho_request(request_rec *r){  config_t *config = cse_get_module_config(r);  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 ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))    return retval;  /* ap_soft_timeout("servlet request", r); */    if (r->request_config && ! config->alt_session_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 (! cse_open_connection(&s, config, session_index, backup_index,                            now, r->pool)) {    return HTTP_SERVICE_UNAVAILABLE;  }  reuse = write_request(&s, r, config, &keepalive,                        session_index, backup_index,                        ip, session_id);  /*  ap_kill_timeout(r);  */  ap_rflush(r);  if (reuse == CSE_END)    cse_recycle(&s, now);  else    cse_close(&s, "no reuse");  if (reuse == HTTP_SERVICE_UNAVAILABLE)    return reuse;  else    return OK;}/** * Print the statistics for each JVM. */static voidjvm_status(config_t *config, request_rec *r){  int i;  stream_t s;  time_t now = r->request_time;  ap_rputs("<center><table border=2 width='80%'>\n", r);  ap_rputs("<tr><th>Host</th>\n", r);  ap_rputs("    <th>Connect<br>Timeout</th>\n", r);  ap_rputs("    <th>Live<br>Time</th>\n", r);  ap_rputs("    <th>Dead<br>Time</th>\n", r);  ap_rputs("</tr>\n", r);  for (i = 0; i < config->srun_size; i++) {    srun_item_t *srun_item = config->srun_list + i;    srun_t *srun = srun_item->srun;    int port;    char group_buf[1024];    if (! srun)      continue;    port = srun->port;    ap_rputs("<tr>", r);    if (srun_item->id && *srun_item->id &&        srun_item->group && *srun_item->group)      sprintf(group_buf, " (%s, %s)", srun_item->id, srun_item->group_id);    else if (srun_item->group && *srun_item->group)      sprintf(group_buf, " (%s)", srun_item->group_id);    else if (srun_item->id && *srun_item->id)      sprintf(group_buf, " (%s)", srun_item->id);    else      group_buf[0] = 0;    if (cse_open(&s, config, srun_item, r->pool, 0) <= 0) {      ap_rprintf(r, "<td bgcolor='#ff6666'>%d.%s %s:%d%s (down)</td>",                 srun_item->session + 1, group_buf,                 srun->hostname ? srun->hostname : "localhost",                 port, srun_item->is_backup ? "*" : "");    }    else {      ap_rprintf(r, "<td bgcolor='#66ff66'>%d.%s %s:%d%s (ok)</td>",                 srun_item->session + 1, group_buf,                 srun->hostname ? srun->hostname : "localhost",                 port, srun_item->is_backup ? "*" : "");    }    /* This needs to be close, because cse_open doesn't use recycle. */    cse_close(&s, "jvm");        ap_rprintf(r, "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>",               srun->connect_timeout, srun->live_time, srun->dead_time);    ap_rputs("</tr>\n", r);  }  ap_rputs("</table></center>\n", r);}static voidescape_html(char *dst, char *src){  int ch;    for (; (ch = *src); src++) {    switch (ch) {    case '<':      *dst++ = '&';      *dst++ = 'l';      *dst++ = 't';      *dst++ = ';';      break;          case '&':      *dst++ = '&';      *dst++ = 'a';      *dst++ = 'm';      *dst++ = 'p';      *dst++ = ';';      break;          default:      *dst++ = ch;      break;    }  }  *dst = 0;}/** * Print a summary of the configuration so users can understand what's * going on.  Ping the server to check that it's up. */static intcaucho_status(request_rec *r){  config_t *config = cse_get_module_config(r);  web_app_t *app;  location_t *loc;   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[8192];    escape_html(buf, config->error);    ap_rprintf(r, "<h2 color='red'>Error : %s</h2>\n", buf);  }    jvm_status(config, r);  ap_rputs("<p><center><table border=2 cellspacing=0 cellpadding=2 width='80%'>\n", r);  ap_rputs("<tr><th>Host\n", r);  ap_rputs("    <th>url-pattern\n", r);    app = config ? config->applications : 0;  for (; app; app = app->next) {    for (loc = app->locations; loc; loc = loc->next) {      char port[16];      char *host = 0;      if (app->host_alias_length > 0 && app->host_aliases[0]->port > 0)        sprintf(port, ":%d", app->host_aliases[0]->port);      else        port[0] = 0;      if (app->host_alias_length > 0)        host = app->host_aliases[0]->host;          ap_rprintf(r, "<tr bgcolor='#ffcc66'><td>%s%s%s<td>%s%s%s%s%s</tr>\n",                  host ? host : "",                 port,                 *app->prefix ? app->prefix : "/",                 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;}/** * When a child process starts, clear the srun structure so it doesn't * mistakenly think the old sockets areopen. */static voidcse_open_child(server_rec *server, pool *p){  LOG(("[%d] open child\n", getpid()));  cse_close_all();  /* initialize round robin */  if (g_config)    g_config->round_robin_index = -1;}/** * Close all the connections cleanly when the Apache child process exits. * * @param server the Apache server object * @param p the Apache memory pool for the server. */static voidcse_close_child(server_rec *server, pool *p){  LOG(("[%d] close child\n", getpid()));  cse_close_all();    LOG(("[%d] close child done\n", getpid()));}/* * Only needed configuration is pointer to resin.conf */static command_rec caucho_commands[] = {    {"CauchoConfigFile", cse_config_file_command, NULL, RSRC_CONF|ACCESS_CONF, TAKE1,     "Pointer to the Caucho configuration file."},    {"CauchoServerRoot", cse_config_server_root, NULL, RSRC_CONF|ACCESS_CONF, TAKE1,     "The root server directory."},    {"CauchoHost", cse_host_command, NULL, RSRC_CONF|ACCESS_CONF, TAKE12,     "Servlet runner host."},    {"CauchoBackup", cse_backup_command, NULL, RSRC_CONF|ACCESS_CONF, TAKE12,     "Servlet runner backup."},    {"CauchoErrorPage", cse_error_page_command, NULL, RSRC_CONF|ACCESS_CONF, TAKE1,     "Error page when connections fail."},    {NULL}};/* * Caucho right has two content handlers: * caucho-status: summary information for debugging * caucho-request: dispatch a Caucho request */static const handler_rec caucho_handlers[] ={    {"caucho-status", caucho_status},    {"caucho-request", caucho_request},    {NULL}};/*  * module configuration * * cse_clean_jsessionid needs to be at [2] to clean up the ;jsessionid= * dispatch to make urls like /foo;jsessionid=aaaXXX work. * * cse_dispatch itself must be after [2] to make DirectoryIndex work. * cse_dispatch must be before [8] for mod_gzip to work */module caucho_module ={    STANDARD_MODULE_STUFF,    cse_module_init,            /* module initializer */    cse_create_dir_config,      /* per-directory config creator */    NULL,                       /* dir config merger */    cse_create_server_config,   /* server config creator */    NULL,                       /* server config merger */    caucho_commands,            /* command table */    caucho_handlers,            /* [7] list of handlers */    cse_clean_jsessionid,       /* [2] filename-to-URI translation */    NULL,                       /* [5] check/validate user_id */    NULL,                       /* [6] check user_id is valid *here* */    NULL,                       /* [4] check access by host address */    cse_dispatch,               /* [7] MIME type checker/setter */    NULL,                       /* [8] fixups */    NULL,                       /* [10] logger */    NULL,                       /* [3] header parser */    cse_open_child,             /* apache child process init */    cse_close_child,            /* apache child process exit/cleanup */    NULL,                       /* [1] post read_request handling */#ifdef EAPI    NULL,                       /* add_module */    NULL,                       /* del_module */    NULL,                       /* rewrite_command */    NULL,                       /* new_connection */#endif    };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -