📄 mod_caucho.c
字号:
/* * Copyright (c) 1998-2002 Caucho Technology -- all rights reserved * * Caucho Technology permits modification and use of this file in * source and binary form ("the Software") subject to the Caucho * Developer Source License 1.1 ("the License") which accompanies * this file. The License is also available at * http://www.caucho.com/download/cdsl1-1.xtp * * In addition to the terms of the License, 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. Each copy of the Software in source or binary form must include * an unmodified copy of the License in a plain ASCII text file named * LICENSE. * * 3. Caucho reserves all rights to its names, trademarks and logos. * In particular, the names "Resin" and "Caucho" are trademarks of * Caucho and may not be used to endorse products derived from * this software. "Resin" and "Caucho" may not appear in the names * of products derived from this software. * * 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 */#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 "cse.h"#include "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 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}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(("%s\n", buf)); config->error = cse_strdup(config->p, buf); config->disable_caucho_status = 0;}voidcse_set_socket_cleanup(int socket, void *pool){ LOG(("set cleanup %d\n", socket)); if (socket > 0) ap_note_cleanups_for_socket(pool, socket);}voidcse_kill_socket_cleanup(int socket, void *pool){ LOG(("kill cleanup %d\n", socket)); if (socket > 0) 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 = (config_t *) malloc(sizeof(config_t)); srun_item_t *srun_list = (srun_item_t *) malloc(16 * sizeof(srun_item_t)); memset(config, 0, sizeof(config_t)); memset(srun_list, 0, 16 * sizeof(srun_item_t)); config->p = cse_create_pool(config); config->srun_list = srun_list; config->srun_capacity = 16; config->srun_size = 0; config->session_url_prefix = ";jsessionid="; config->session_cookie = "JSESSIONID="; config->round_robin_index = -1; g_config = config; return (void *) config;}static void *cse_create_dir_config(pool *p, char *dir){ config_t *config = (config_t *) malloc(sizeof(config_t)); srun_item_t *srun_list = (srun_item_t *) malloc(16 * sizeof(srun_item_t)); memset(config, 0, sizeof(config_t)); memset(srun_list, 0, 16 * sizeof(srun_item_t)); config->p = cse_create_pool(config); config->srun_list = srun_list; config->srun_capacity = 16; config->srun_size = 0; config->session_url_prefix = ";jsessionid="; config->session_cookie = "JSESSIONID="; config->path = "no-assigned-path"; config->round_robin_index = -1; 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 CauchoConfigHost configuration in the apache config file. */static const char *cse_config_file_command(cmd_parms *cmd, void *mconfig, char *value){ config_t *config = cse_get_cmd_config(cmd); config->path = ap_server_root_relative(cmd->pool, value); cse_init_config(config); return 0;}/** * 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; 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 *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_backup(config, 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_prefix) { if (! strncmp(uri + 1, config->alt_session_prefix, config->alt_session_prefix_length)) { 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_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;}/** * Look at the request to see if Caucho should handle it. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -