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

📄 nsapi.c

📁 解压在c盘
💻 C
📖 第 1 页 / 共 2 页
字号:
  return code;}static intwrite_request(stream_t *s, Session *sn, Request *rq, config_t *config){  int content_length;  int code;  char buf[BUF_LENGTH + 1];  int isFirst = 1;  netbuf *inbuf = sn->inbuf;  write_env(s, sn, rq);    write_headers(s, sn, rq, &content_length);  /* read post data */  while (content_length > 0) {    int len;    if (inbuf->pos >= inbuf->cursize) {      if (netbuf_grab(inbuf, BUF_LENGTH) <= 0)	return 0;    }    len = inbuf->cursize - inbuf->pos;    if (BUF_LENGTH < len)      len = BUF_LENGTH;    if (len <= 0)      return 0;        memcpy(buf, inbuf->inbuf + inbuf->pos, len);    inbuf->pos += len;    content_length -= len;    buf[len] = 0;        cse_write_packet(s, CSE_DATA, buf, len);    if (! isFirst) {      code = send_data(s, sn, rq, CSE_ACK);      if (code < 0 || code == CSE_END || code == CSE_CLOSE)	break;    }    isFirst = 0;  }  cse_write_packet(s, CSE_END, 0, 0);  code = send_data(s, sn, rq, CSE_END);    return code == CSE_END;}static voidnet_printf(Session *sn, char *fmt, ...){  va_list args;  char buf[4096];    va_start(args, fmt);  vsprintf(buf, fmt, args);  va_end(args);  net_write(sn->csd, buf, strlen(buf));}static voidconnection_error(config_t *config, srun_item_t *srun_item, Session *sn, Request *rq){  srun_t *srun = srun_item->srun;  int fd = -1;  /* Writing of error_page added by Jose Manuel Cantera Fonseca */  if (config->error_page)    fd = open(config->error_page, O_RDONLY);    if (fd >= 0) {    char buf[1024];    int len;    while ((len = read(fd, buf, sizeof(buf))) > 0)      net_write(sn->csd, buf, len);    close(fd);  }  else {    net_printf(sn, "<html><body bgcolor='white'>\n");    net_printf(sn, "<h1>Cannot contact servlet runner at %s:%d</h1>\n",                srun->hostname ? srun->hostname : "localhost",               srun->port);    net_printf(sn, "</body></html>\n");  }}static intget_session_index(Request *rq, int *backup){  int i;  int session;  char *uri;  for (i = 0; i < rq->headers->hsize; i++) {    struct pb_entry *entry = rq->headers->ht[i];    for (; entry; entry = entry->next) {      char *name = entry->param->name;      char *value = entry->param->value;      if (strcasecmp(name, "cookie"))	continue;      session = cse_session_from_string(value, "JSESSIONID=", backup);      if (session >= 0)	return session;    }  }  uri = pblock_findval("uri", rq->reqpb);    return cse_session_from_string(uri, g_config->session_url_prefix, backup);}static voidcse_init(char *resin_conf){  g_lock = crit_init();      crit_enter(g_lock);      if (! g_config) {    g_static_config.path = resin_conf;    cse_init_config(&g_static_config);        g_config = &g_static_config;  }      crit_exit(g_lock);}NSAPI_PUBLIC intcaucho_filter(pblock *pb, Session *sn, Request *rq){  char *host = 0;  char hostbuf[8096];  int port;  char *uri = 0;  LOG(("start caucho_filter\n"));  if (! g_config) {    char *conf = pblock_findval("conf", pb);    if (conf)      cse_init(conf);    else      cse_init("c:\resin1.1");  }    cse_update_config(g_config, rq->req_start);    if (request_header("host", &host, sn, rq) == REQ_PROCEED && host) {    char *p;    strncpy(hostbuf, host, sizeof(hostbuf));    hostbuf[sizeof(hostbuf) - 1] = 0;    p = strchr(hostbuf, ':');        if (p) {      port = atoi(p + 1);      *p = 0;    }    else      port =  conf_getglobals()->Vport;  }  else {    char *hostname = util_hostname();    strcpy(hostbuf, hostname ? hostname : "");    port =  conf_getglobals()->Vport;  }  uri = pblock_findval("uri", rq->reqpb);  if (! uri)    uri = "/";    if (cse_match_request(g_config, hostbuf, port, uri, 1)) {    param_free(pblock_remove("name", rq->vars));    pblock_nvinsert("name", "resin", rq->vars);    return REQ_PROCEED;  }    return REQ_NOACTION;}NSAPI_PUBLIC intcaucho_service(pblock *pb, Session *sn, Request *rq){  stream_t s;  int reuse;  int session_index = -1;  char *ip = "";  int rand = 0;  int backup = -1;  LOG(("start caucho_service\n"));  if (! g_config) {    char *conf = pblock_findval("conf", pb);    if (conf)      cse_init(conf);    else      cse_init("c:\\resin1.1");  }  cse_update_config(g_config, rq->req_start);    param_free(pblock_remove("content-type", rq->srvhdrs));    session_index = get_session_index(rq, &backup);   if (! cse_open_connection(&s, g_config, session_index, backup,                            rq->req_start, 0)) {    connection_error(g_config, g_config->srun_list, sn, rq);      return REQ_PROCEED;  }  reuse = write_request(&s, sn, rq, g_config);  /*  //ap_kill_timeout(r);  //ap_rflush(r);  */  if (reuse)    cse_recycle(&s, rq->req_start);  else    cse_close(&s, "no reuse");  return REQ_PROCEED;}static voidjvm_status(config_t *config, Session *sn){  int i;  stream_t s;  net_printf(sn, "<center><table border=2 cellspacing=0 cellpadding=2 width='60%%'>\n");  net_printf(sn, "<tr><th>Host</th>\n");  net_printf(sn, "    <th>Connect<br>Timeout</th>\n");  net_printf(sn, "    <th>Live<br>Time</th>\n");  net_printf(sn, "    <th>Dead<br>Time</th>\n");  net_printf(sn, "</tr>\n");  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;    if (! srun)      return;    port = srun->port;    net_printf(sn, "<tr>");    if (! cse_open(&s, config, srun_item, 0, 1)) {      net_printf(sn, "<td bgcolor='#ff6666'>%s:%d%s (down)</td>",		 srun->hostname ? srun->hostname : "localhost",		 port, srun_item->is_backup ? "*" : "");    }    else {      net_printf(sn, "<td bgcolor='#66ff66'>%s:%d%s (ok)</td>",		 srun->hostname ? srun->hostname : "localhost",		 port, srun_item->is_backup ? "*" : "");      net_printf(sn, "<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td>",                 srun->connect_timeout, srun->live_time, srun->dead_time);            cse_close(&s, "caucho-status");      continue;    }  }  net_printf(sn, "</table></center>\n");}NSAPI_PUBLIC intcaucho_status(pblock *pb, Session *sn, Request *rq){  web_app_t *app;  location_t *loc;  LOG(("start caucho_status\n"));  if (! g_config) {    char *conf = pblock_findval("conf", pb);	if (conf)		cse_init(conf);	else		cse_init("c:\\resin1.1");  }    cse_update_config(g_config, rq->req_start);  param_free(pblock_remove("content-type", rq->srvhdrs));  pblock_nvinsert("content-type", "text/html", rq->srvhdrs);  net_printf(sn, "<html><title>Status : Caucho Servlet Engine</title>\n");  net_printf(sn, "<body bgcolor=white>\n");  net_printf(sn, "<h1>Status : Caucho Servlet Engine</h1>\n");    jvm_status(g_config, sn);  net_printf(sn, "<p><center><table border=2 cellspacing=0 cellpadding=2 width='60%%'>\n");  net_printf(sn, "<tr><th width='50%%'>Host\n");  net_printf(sn, "    <th>url-pattern\n");    app = g_config ? g_config->applications : 0;  for (; app; app = app->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;    for (loc = app->locations; loc; loc = loc->next) {      net_printf(sn, "<tr bgcolor='#ffcc66'><td>%s%s%s<td>%s%s%s%s%s</tr>\n",                  host ? host : "",                 port,                 app->prefix,                 loc->prefix,                 ! loc->is_exact && ! loc->suffix ? "/*" :                  loc->suffix && loc->prefix[0] ? "/" : "",                 loc->suffix ? "*" : "",                 loc->suffix ? loc->suffix : "",                 loc->ignore ? " (ignore)" : "");    }  }  net_printf(sn, "</table></center>\n");  net_printf(sn, "</body></html>\n");  return REQ_PROCEED;}

⌨️ 快捷键说明

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