📄 mod_caucho.c
字号:
/* * Copyright (c) 1999-2008 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 */#include <sys/types.h>#include <errno.h>#ifndef WIN32#include <unistd.h>#endif#include "ap_config.h"#include "apr_strings.h"#include "httpd.h"#include "http_config.h"#include "http_core.h"#include "http_protocol.h"#include "http_connection.h"#ifdef DEBUG#include <time.h>#endif#include "cse.h"#include "version.h"#if ! 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;static time_t g_start_time;#define DEFAULT_PORT 6802voidcse_log(char *fmt, ...){#ifdef DEBUG va_list args; char timestamp[32]; char buffer[8192]; time_t t; int pid; FILE *file; file = fopen("/tmp/mod_caucho.log", "a"); pid = (int) getpid(); time(&t); strftime(timestamp, sizeof(timestamp), "[%m/%b/%Y:%H:%M:%S %z]", localtime(&t));#if APR_HAS_THREADS snprintf(buffer, sizeof(buffer), "%s %d_%ld: ", timestamp, pid, (long int) apr_os_thread_current());#else snprintf(buffer, sizeof(buffer), "%s %d: ", timestamp, pid);#endif va_start(args, fmt); vsprintf(buffer + strlen(buffer), fmt, args); va_end(args); if (file) { fputs(buffer, file); fclose(file); } else { fputs(buffer, stderr); fflush(stderr); }#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;}voidcse_free_lock(config_t *config, void *vlock){ apr_thread_mutex_destroy(vlock);}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(("ERROR: %s\n", buf)); if (config->error && *config->error) free(config->error); config->error = strdup(buf);}voidcse_set_socket_cleanup(int socket, void *pool){ /* XXX: LOG(("set cleanup %d\n", socket)); 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_init_server_config(apr_pool_t *p, char *dummy){ ap_add_version_component(p, VERSION); return 0;}static void *cse_create_server_config(apr_pool_t *p, server_rec *s){ config_t *config = (config_t *) apr_pcalloc(p, sizeof(config_t)); memset(config, 0, sizeof(config_t)); config->web_pool = p; config->start_time = g_start_time; cse_init_config(config); return (void *) config;}static void *cse_merge_server_config(apr_pool_t *p, void *basev, void *overridesv){ config_t *base = (config_t *) basev; config_t *overrides = (config_t *) overridesv; if (! overrides || ! overrides->has_config) return base; else return overrides;}static void *cse_create_dir_config(apr_pool_t *p, char *path){ config_t *config = (config_t *) apr_pcalloc(p, sizeof(config_t)); memset(config, 0, sizeof(config_t)); config->web_pool = p; cse_init_config(config); return (void *) config;}static void *cse_merge_dir_config(apr_pool_t *p, void *basev, void *overridesv){ config_t *base = (config_t *) basev; config_t *overrides = (config_t *) overridesv; if (! overrides || ! overrides->has_config) return base; else return overrides;}/** * 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 && config->has_config) return config; if (r->server->module_config) config = (config_t *) ap_get_module_config(r->server->module_config, &caucho_module); return config;}/** * Retrieves the caucho configuration from Apache */static config_t *cse_get_server_config(server_rec *s){ config_t *config; config = (config_t *) ap_get_module_config(s->module_config, &caucho_module); return config;}/** * Parse the CauchoHosts configuration in the apache config file. */static const char *resin_config_server_command(cmd_parms *cmd, void *pconfig, const char *host_arg, const char *port_arg){ config_t *config = pconfig; /* cse_get_server_config(cmd->server); */ int port = port_arg ? atoi(port_arg) : DEFAULT_PORT; if (! config) return 0; config->has_config = 1; /* cse_add_host(&config->config_cluster, host_arg, port); */ if (! strcmp(host_arg, "current")) { char hostname[256]; gethostname(hostname, sizeof(hostname)); host_arg = strdup(host_arg); } cse_add_config_server(config->p, config, host_arg, port); return 0;}/** * Parse the CauchoStatus configuration in the apache config file. */static const char *caucho_status_command(cmd_parms *cmd, void *pconfig, const char *value){ config_t *config = pconfig; /* = cse_get_server_config(cmd->server); */ if (! config) return 0; config->has_config = 1; if (value == 0 || ! strcmp(value, "true") || ! strcmp(value, "yes")) config->enable_caucho_status = 1; else config->enable_caucho_status = 0; return 0;}/** * Parse the CauchoConfigCacheDirectory configuration in the apache config file. */static const char *resin_config_cache_command(cmd_parms *cmd, void *pconfig, const char *cache_dir){ config_t *config = pconfig; /* cse_get_server_config(cmd->server); */ if (! config || ! cache_dir) return 0; config->has_config = 1; strcpy(config->work_dir, cache_dir); return 0;}/** * Parse the CauchoConfigHost configuration in the apache config file. */static const char *cse_config_file_command(cmd_parms *cmd, void *pconfig, char *value){ return "CauchoConfigFile has been replaced by ResinConfigServer.\n";}/** * Parse the CauchoHosts configuration in the apache config file. */static const char *cse_host_command(cmd_parms *cmd, void *pconfig, const char *host_arg, const char *port_arg){ config_t *config = pconfig; /* = cse_get_server_config(cmd->server); */ int port = port_arg ? atoi(port_arg) : DEFAULT_PORT; resin_host_t *host; if (! config) return 0; config->has_config = 1; 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 *pconfig, const char *host_arg, const char *port_arg){ config_t *config = pconfig; /* = cse_get_server_config(cmd->server); */ int port = port_arg ? atoi(port_arg) : DEFAULT_PORT; resin_host_t *host; if (! config) return 0; config->has_config = 1; 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->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;}/** * Set the default session cookie used by mod_caucho. */static const char *resin_session_cookie_command(cmd_parms *cmd, void *pconfig, const char *cookie_arg){ config_t *config = pconfig; /* = cse_get_server_config(cmd->server); */ if (! config) return 0; config->has_config = 1; strcpy(config->session_cookie, cookie_arg);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -