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

📄 mod_caucho.c

📁 resinweb服务器源文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1999-2002 Caucho Technology.  All rights reserved. * * Caucho Technology permits redistribution, modification and use * of this file in source and binary form ("the Software") under the * Caucho Developer Source License ("the License").  In particular, * the following conditions must be met: * * 1. Each copy or derived work of the Software must preserve the copyright *    notice and this notice unmodified. * * 2. Redistributions of the Software in source or binary form must include  *    an unmodified copy of the License, normally in a plain ASCII text * * 3. The names "Resin" or "Caucho" are trademarks of Caucho Technology and *    may not be used to endorse products derived from this software. *    "Resin" or "Caucho" may not appear in the names of products derived *    from this software. * * 4. Caucho Technology requests that attribution be given to Resin *    in any manner possible.  We suggest using the "Resin Powered" *    button or creating a "powered by Resin(tm)" link to *    http://www.caucho.com for each page served by Resin. * * This Software is provided "AS IS," without a warranty of any kind.  * ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. * * CAUCHO TECHNOLOGY AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE OR ANY THIRD PARTY AS A RESULT OF USING OR * DISTRIBUTING SOFTWARE. IN NO EVENT WILL CAUCHO OR ITS LICENSORS BE LIABLE * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE SOFTWARE, EVEN IF HE HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGES. * * @author Scott Ferguson */#include "httpd.h"#include "http_config.h"#include "http_core.h"#include "http_protocol.h"#include "ap_config.h"#include "apr_strings.h"#include "apr_thread_mutex.h"#include <stdlib.h>#include <errno.h>#include "cse.h"#include "version.h"#ifndef APR_HAS_THREADS#define apr_thread_mutex_t int#define apr_thread_mutex_create(a,b,c)#define apr_thread_mutex_lock(a)#define apr_thread_mutex_unlock(a)#endif/* * Apache magic module declaration. */module AP_MODULE_DECLARE_DATA caucho_module;#define BUF_LENGTH 8192#define DEFAULT_PORT 6802static char *g_error_page = 0;voidcse_log(char *fmt, ...){#ifdef DEBUG  va_list args;  FILE *file = fopen("/tmp/log", "a+");  if (file) {      va_start(args, fmt);    vfprintf(file, fmt, args);    va_end(args);    fclose(file);  }#endif}void *cse_create_lock(config_t *config){  apr_thread_mutex_t *lock = 0;  apr_thread_mutex_create(&lock, APR_THREAD_MUTEX_DEFAULT,                          config->web_pool);  return lock;}intcse_lock(void *vlock){  apr_thread_mutex_t *lock = vlock;  if (lock)    apr_thread_mutex_lock(lock);    return 1;}voidcse_unlock(void *vlock){  apr_thread_mutex_t *lock = vlock;  if (lock)    apr_thread_mutex_unlock(lock);}voidcse_error(config_t *config, char *format, ...){  char buf[BUF_LENGTH];  va_list args;  va_start(args, format);  vsprintf(buf, format, args);  va_end(args);  LOG(("%s\n", buf));  config->error = cse_strdup(config->p, buf);}voidcse_set_socket_cleanup(int socket, void *pool){  LOG(("set cleanup %d\n", socket));  /* XXX:  if (socket > 0)    apr_note_cleanups_for_socket(pool, socket);  */}voidcse_kill_socket_cleanup(int socket, void *pool){  /* XXX:  LOG(("kill cleanup %d\n", socket));  if (socket > 0)    apr_kill_cleanups_for_socket(pool, socket);  */}void *cse_malloc(int size){  return malloc(size);}void cse_free(config_t *config, void *data) {}static void *cse_create_dir_config(apr_pool_t *p, char *dummy){  config_t *config = (config_t *) apr_pcalloc(p, sizeof(config_t));  srun_item_t *srun_list = (srun_item_t *) apr_pcalloc(p, 16 * sizeof(srun_item_t));  memset(config, 0, sizeof(config_t));  memset(srun_list, 0, 16 * sizeof(srun_item_t));  config->web_pool = p;  config->p = cse_create_pool(config);  config->srun_list = srun_list;  config->srun_capacity = 16;  config->srun_size = 1;  config->session_url_prefix = ";jsessionid=";  config->session_cookie = "JSESSIONID=";  config->path = "no-assigned-path";  config->round_robin_index = -1;    return (void *) config;}/** * Retrieves the caucho configuration from Apache */static config_t *cse_get_module_config(request_rec *r){  config_t *config;  LOG(("get config %x\n", r->per_dir_config));  config = (config_t *) ap_get_module_config(r->per_dir_config,                                             &caucho_module);  return config;}/** * Parse the CauchoConfigHost configuration in the apache config file. */static const char *cse_config_file_command(cmd_parms *cmd, void *pconfig, char *value){  config_t *config = pconfig;  if (! config)    return 0;   config->path = (char *) ap_server_root_relative(cmd->pool, value);  cse_init_config(config);  return 0;}/** * Parse the server root. */static const char *cse_server_root_command(cmd_parms *cmd, void *pconfig, char *value){  config_t *config = pconfig;   if (! config)    return 0;    config->resin_home = ap_server_root_relative(cmd->pool, value);  return 0;}/** * Parse the CauchoHosts configuration in the apache config file. */static const char *cse_host_command(cmd_parms *cmd, void *pconfig, char *host_arg, char *port_arg){  config_t *config = pconfig;  int port = port_arg ? atoi(port_arg) : DEFAULT_PORT;    if (! config)    return 0;    cse_add_host(config, host_arg, port);  return 0;}/** * Parse the CauchoBackup configuration in the apache config file. */static const char *cse_backup_command(cmd_parms *cmd, void *pconfig,		   char *host_arg, char *port_arg){  config_t *config = pconfig;  int port = port_arg ? atoi(port_arg) : DEFAULT_PORT;  if (! config)    return 0;  cse_add_backup(config, host_arg, port);  return 0;}/** * Gets the session index from the request * * Cookies have priority over the query * * @return -1 if no session */static intget_session_index(config_t *config, request_rec *r, int *backup){  const apr_array_header_t *header = apr_table_elts(r->headers_in);  const apr_table_entry_t *headers = (const apr_table_entry_t *) header->elts;  int i;  int session;  for (i = 0; i < header->nelts; ++i) {    if (! headers[i].key || ! headers[i].val)      continue;    if (strcasecmp(headers[i].key, "Cookie"))      continue;    session = cse_session_from_string(headers[i].val,                                      config->session_cookie,                                      backup);    if (session >= 0)      return session;  }  return cse_session_from_string(r->uri, config->session_url_prefix, backup);}/** * Forward to an error page. */static inthandle_include(char *uri, request_rec *r){#ifdef XXX    request_rec *subrequest = ap_sub_req_lookup_uri(uri, r);  int status;  LOG(("forwarding %s %d\n", uri, subrequest->status));    if (subrequest->status != HTTP_OK)    return -1;  /* copy the args from the original request */  subrequest->path_info = r->path_info;  subrequest->args = r->args;  /* Run it. */  status = ap_run_sub_req(subrequest);  ap_destroy_sub_req(subrequest);  return status;#endif  return -1;}static intconnection_error(config_t *config, srun_t *srun, request_rec *r){  char *error_page = config->error_page;    if (g_error_page)    error_page = g_error_page;  if (error_page) {    int status;    r->status = 503;    status = handle_include(error_page, r);    if (status == OK)      return status;  }  r->content_type = "text/html";  if (error_page) {    r->status = 302;    apr_table_set(r->headers_out, "Location",                  apr_pstrdup(r->pool, error_page));  }  else    r->status = 503;  ap_rputs("<html><body bgcolor='white'>", r);  if (! srun) {    ap_rprintf(r, "<h1>Can't contact servlet runner</h1>");  }  else    ap_rprintf(r, "<h1>Can't contact servlet runner at %s:%d</h1>",                srun->hostname ? srun->hostname : "localhost",               srun->port);  ap_rputs("</body></html>", r);    ap_rputs("\n\n\n\n", r);  ap_rputs("<!--\n", r);  ap_rputs("   - Unfortunately, Microsoft has added a clever new\n", r);  ap_rputs("   - \"feature\" to Internet Explorer.  If the text in\n", r);  ap_rputs("   - an error's message is \"too small\", specifically\n", r);  ap_rputs("   - less than 512 bytes, Internet Explorer returns\n", r);  ap_rputs("   - its own error message.  Yes, you can turn that\n", r);  ap_rputs("   - off, but *surprise* it's pretty tricky to find\n", r);  ap_rputs("   - buried as a switch called \"smart error\n", r);  ap_rputs("   - messages\"  That means, of course, that many of\n", r);  ap_rputs("   - Resin's error messages are censored by default.\n", r);  ap_rputs("   - And, of course, you'll be shocked to learn that\n", r);  ap_rputs("   - IIS always returns error messages that are long\n", r);  ap_rputs("   - enough to make Internet Explorer happy.  The\n", r);  ap_rputs("   - workaround is pretty simple: pad the error\n", r);  ap_rputs("   - message with a big comment to push it over the\n", r);  ap_rputs("   - five hundred and twelve byte minimum.  Of course,\n", r);  ap_rputs("   - that's exactly what you're reading right now.\n", r);  ap_rputs("   -->\n", r);  return OK;}/** * Writes request parameters to srun. */static voidwrite_env(stream_t *s, request_rec *r){  char buf[4096];  int ch;  int i;    conn_rec *c = r->connection;  const char *host;  int port;  cse_write_string(s, CSE_PROTOCOL, r->protocol);  cse_write_string(s, CSE_METHOD, r->method);  for (i = 0; (ch = r->uri[i]) && ch != '?' && i + 1 < sizeof(buf); i++)     buf[i] = ch;  buf[i] = 0;  cse_write_string(s, CSE_URI, buf);  if (r->args)    cse_write_string(s, CSE_QUERY_STRING, r->args);  /* Gets the server name */  host = ap_get_server_name(r);  port = ap_get_server_port(r);  cse_write_string(s, CSE_SERVER_NAME, host);  sprintf(buf, "%u", port);  cse_write_string(s, CSE_SERVER_PORT, buf);  if (c->remote_host)    cse_write_string(s, CSE_REMOTE_HOST, c->remote_host);  else    cse_write_string(s, CSE_REMOTE_HOST, c->remote_ip);  cse_write_string(s, CSE_REMOTE_ADDR, c->remote_ip);  sprintf(buf, "%u", ntohs(c->remote_addr->port));  cse_write_string(s, CSE_REMOTE_PORT, buf);  if (r->user)    cse_write_string(s, CSE_REMOTE_USER, r->user);  if (r->ap_auth_type)    cse_write_string(s, CSE_AUTH_TYPE, r->ap_auth_type);  sprintf(buf, "%d", s->srun->session);  cse_write_string(s, CSE_SESSION_GROUP, buf);  /* mod_ssl */#ifdef EAPI  {    static char *vars[] = { "SSL_CLIENT_S_DN",                            "SSL_CIPHER",                            "SSL_CIPHER_EXPORT",                            "SSL_PROTOCOL",                            "SSL_CIPHER_USEKEYSIZE",                            "SSL_CIPHER_ALGKEYSIZE",                            0};    char *var;    int i;    int v;        if ((v = ap_hook_call("ap::mod_ssl::var_lookup", &var, r->pool, r->server,                          r->connection, r, "SSL_CLIENT_CERT"))) {      cse_write_string(s, CSE_CLIENT_CERT, var);    }    for (i = 0; vars[i]; i++) {      if ((v = ap_hook_call("ap::mod_ssl::var_lookup", &var,                            r->pool, r->server, r->connection, r, vars[i]))) {        cse_write_string(s, CSE_HEADER, vars[i]);        cse_write_string(s, CSE_VALUE, var);      }    }  }#endif  }/** * Writes headers to srun. */static voidwrite_headers(stream_t *s, request_rec *r){  const apr_array_header_t *header = apr_table_elts(r->headers_in);  apr_table_entry_t *headers = (apr_table_entry_t *) header->elts;  int i;  for (i = 0; i < header->nelts; ++i) {    if (! headers[i].key)

⌨️ 快捷键说明

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