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

📄 mod_caucho.c

📁 RESIN 3.2 最新源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 1998-2003 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT.  See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * *   Free Software Foundation, Inc. *   59 Temple Place, Suite 330 *   Boston, MA 02111-1307  USA * * @author Scott Ferguson */#ifndef WIN32#include "ap_config_auto.h"#endif#include "httpd.h"#include "http_config.h"#include "http_request.h"#include "http_core.h"#include "http_protocol.h"#include "http_log.h"#include "http_main.h"#include "util_script.h"#include <stdlib.h>#include <errno.h>#if !defined(EAPI) && (MODULE_MAGIC_COOKIE == MODULE_MAGIC_COOKIE_EAPI)#define EAPI 1#endif#include "../common/cse.h"#include "../common/version.h"/* * Apache magic module declaration. */module MODULE_VAR_EXPORT caucho_module;#define DEFAULT_PORT 6802static char *g_error_page = 0;static config_t *g_config = 0;static pool *g_pool = 0;static char session_decode[128];voidcse_log(char *fmt, ...){#ifdef DEBUG  va_list args;  FILE *file = fopen("/tmp/log", "a+");  if (file) {      time_t now = time(0);    struct tm *now_tm = localtime(&now);    char date[80];        strftime(date, sizeof(date), "%H:%M:%S", now_tm);    fprintf(file, "%d:[%s] ", getpid(), date);    va_start(args, fmt);    vfprintf(file, fmt, args);    va_end(args);    fclose(file);  }#endif}void *cse_create_lock(config_t *config){#ifdef WIN32	return CreateMutex(0, 0, 0);#else    return 0;#endif}voidcse_free_lock(config_t *config, void *vlock){}intcse_lock(void *lock){#ifdef WIN32  if (lock) {    WaitForSingleObject(lock, INFINITE);  }  return 1;#else  return 1;#endif}voidcse_unlock(void *lock){#ifdef WIN32	if (lock)		ReleaseMutex(lock);#endif}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(("ERROR: %s\n", buf));  config->error = cse_strdup(config->p, buf);}voidcse_set_socket_cleanup(int socket, void *pool){  LOG(("set cleanup %d\n", socket));  if (socket > 0 && pool)    ap_note_cleanups_for_socket(pool, socket);}voidcse_kill_socket_cleanup(int socket, void *pool){  LOG(("kill cleanup %d\n", socket));  if (socket > 0 && pool)    ap_kill_cleanups_for_socket(pool, socket);}void *cse_malloc(int size){  return malloc(size);}void cse_free(void *data) {}static voidcse_module_init(struct server_rec *server, struct pool *pool){  ap_add_version_component(VERSION);}static void *cse_create_server_config(pool *p, server_rec *server){  config_t *config;  if (! g_pool)    g_pool = ap_make_sub_pool(p);  config = (config_t *) ap_pcalloc(g_pool, sizeof(config_t));  memset(config, 0, sizeof(config_t));  config->web_pool = g_pool;  cse_init_config(config);  g_config = config;    return (void *) config;}static void *cse_create_dir_config(pool *p, char *dir){  config_t *config;  if (! g_pool)    g_pool = ap_make_sub_pool(p);  config = (config_t *) ap_pcalloc(g_pool, sizeof(config_t));  memset(config, 0, sizeof(config_t));  config->web_pool = g_pool;  cse_init_config(config);  if (! g_config)    g_config = config;    return (void *) config;}/** * Retrieves the caucho configuration from Apache */static config_t *cse_get_module_config(request_rec *r){  config_t *config = 0;  if (r->per_dir_config)    config = (config_t *) ap_get_module_config(r->per_dir_config, &caucho_module);  if (config)    return config;  if (r->server->module_config)    config = (config_t *) ap_get_module_config(r->server->module_config,                                               &caucho_module);  if (config)    return config;  else    return g_config;}static config_t *cse_get_cmd_config(cmd_parms *cmd){  config_t *config = (config_t *) ap_get_module_config(cmd->context, &caucho_module);  if (config)    return config;    config = (config_t *) ap_get_module_config(cmd->server->module_config,                                             &caucho_module);  if (config)    return config;  else    return g_config;}/** * Parse the ResinConfigServer configuration in the apache config file. */static const char *cse_config_server_command(cmd_parms *cmd, void *mconfig,			  char *host_arg, char *port_arg){  config_t *config = cse_get_cmd_config(cmd);  int port = port_arg ? atoi(port_arg) : DEFAULT_PORT;  /*  cse_add_host(&config->config_cluster, host_arg, port);  */  cse_add_config_server(config->p, config, host_arg, port);  return 0;}/** * Parse the CauchoStatus configuration in the apache config file. */static const char *cse_caucho_status_command(cmd_parms *cmd, void *pconfig, char *value){  config_t *config = cse_get_cmd_config(cmd);    if (! config)    return 0;    if (value == 0 || ! strcmp(value, "true") || ! strcmp(value, "yes"))    config->enable_caucho_status = 1;  else    config->enable_caucho_status = 0;  return 0;}/** * Parse the CauchoConfigHost configuration in the apache config file. */static const char *cse_config_file_command(cmd_parms *cmd, void *mconfig, char *value){  return "CauchoConfigFile has been replaced by ResinConfigServer.\n";}/** * Parse the server root. */static const char *cse_config_server_root(cmd_parms *cmd, void *mconfig, char *value){  config_t *config = cse_get_cmd_config(cmd);   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 *mconfig, char *host_arg, char *port_arg){  config_t *config = cse_get_cmd_config(cmd);  int port = port_arg ? atoi(port_arg) : DEFAULT_PORT;  resin_host_t *host;  host = config->manual_host;  if (! host) {    host = cse_alloc(config->p, sizeof(resin_host_t));    memset(host, 0, sizeof(resin_host_t));        host->name = "manual";    host->canonical = host;    host->config = config;        host->cluster.config = config;    host->cluster.round_robin_index = -1;        config->manual_host = host;  }  cse_add_host(config->p, &host->cluster, host_arg, port);  return 0;}/** * Parse the CauchoBackup configuration in the apache config file. */static const char *cse_backup_command(cmd_parms *cmd, void *mconfig,		   char *host_arg, char *port_arg){  config_t *config = cse_get_cmd_config(cmd);  int port = port_arg ? atoi(port_arg) : DEFAULT_PORT;  resin_host_t *host;  host = config->manual_host;  if (! host) {    host = cse_alloc(config->p, sizeof(resin_host_t));    memset(host, 0, sizeof(resin_host_t));        host->name = "manual";    host->canonical = host;    host->config = config;        host->cluster.config = config;    host->cluster.round_robin_index = -1;        config->manual_host = host;  }  cse_add_backup(config->p, &host->cluster, host_arg, port);  return 0;}/** * Parse the CauchoKeepalive configuration in the apache config file. */static const char *cse_keepalive_command(cmd_parms *cmd, void *mconfig, int flag){  /* g_srun_keepalive = flag; */  return 0;}/** * Parse the CauchoHosts configuration in the apache config file. */static const char *cse_error_page_command(cmd_parms *cmd, void *mconfig, char *error_page_arg){  g_error_page = error_page_arg;  return 0;}/** * Look at the request to see if Caucho should handle it. */static intcse_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,

⌨️ 快捷键说明

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