📄 mod_jk.c
字号:
return "JkUnMount can not have a path when defined in a location";
}
if (c[0] != '/')
return "JkUnMount context should start with /";
uri = apr_pstrcat(cmd->temp_pool, "!", c, NULL);
/*
* Add the new worker to the alias map.
*/
jk_map_put(conf->uri_to_context, uri, w, NULL);
return NULL;
}
/*
* JkAutoMount directive handling
*
* JkAutoMount worker [virtualhost]
* This is an experimental and undocumented extension made in j-t-c/jk.
*/
static const char *jk_automount_context(cmd_parms * cmd,
void *dummy,
const char *worker,
const char *virtualhost)
{
server_rec *s = cmd->server;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
/*
* Add the new automount to the auto map.
*/
jk_map_put(conf->automount, worker, virtualhost, NULL);
return NULL;
}
/*
* JkWorkersFile Directive Handling
*
* JkWorkersFile file
*/
static const char *jk_set_worker_file(cmd_parms * cmd,
void *dummy, const char *worker_file)
{
server_rec *s = cmd->server;
struct stat statbuf;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
/* we need an absolut path (ap_server_root_relative does the ap_pstrdup) */
conf->worker_file = ap_server_root_relative(cmd->pool, worker_file);
if (conf->worker_file == NULL)
return "JkWorkersFile file_name invalid";
if (stat(conf->worker_file, &statbuf) == -1)
return "Can't find the workers file specified";
return NULL;
}
/*
* JkMountFile Directive Handling
*
* JkMountFile file
*/
static const char *jk_set_mount_file(cmd_parms * cmd,
void *dummy, const char *mount_file)
{
server_rec *s = cmd->server;
struct stat statbuf;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
/* we need an absolut path (ap_server_root_relative does the ap_pstrdup) */
conf->mount_file = ap_server_root_relative(cmd->pool, mount_file);
if (conf->mount_file == NULL)
return "JkMountFile file name invalid";
if (stat(conf->mount_file, &statbuf) == -1)
return "Can't find the mount file specified";
return NULL;
}
/*
* JkLogFile Directive Handling
*
* JkLogFile file
*/
static const char *jk_set_log_file(cmd_parms * cmd,
void *dummy, const char *log_file)
{
server_rec *s = cmd->server;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
/* we need an absolute path */
if (*log_file != '|')
conf->log_file = ap_server_root_relative(cmd->pool, log_file);
else
conf->log_file = apr_pstrdup(cmd->pool, log_file);
if (conf->log_file == NULL)
return "JkLogFile file_name invalid";
return NULL;
}
/*
* JkShmFile Directive Handling
*
* JkShmFile file
*/
static const char *jk_set_shm_file(cmd_parms * cmd,
void *dummy, const char *shm_file)
{
/* we need an absolute path */
jk_shm_file = ap_server_root_relative(cmd->pool, shm_file);
if (jk_shm_file == NULL)
return "JkShmFile file name invalid";
return NULL;
}
/*
* JkShmSize Directive Handling
*
* JkShmSize size in kilobytes
*/
static const char *jk_set_shm_size(cmd_parms * cmd,
void *dummy, const char *shm_size)
{
int sz = 0;
/* we need an absolute path */
sz = atoi(shm_size) * 1024;
if (sz < JK_SHM_DEF_SIZE)
sz = JK_SHM_DEF_SIZE;
else
sz = JK_SHM_ALIGN(sz);
jk_shm_size = (size_t)sz;
return NULL;
}
/*
* JkLogLevel Directive Handling
*
* JkLogLevel debug/info/error/emerg
*/
static const char *jk_set_log_level(cmd_parms * cmd,
void *dummy, const char *log_level)
{
server_rec *s = cmd->server;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
conf->log_level = jk_parse_log_level(log_level);
return NULL;
}
/*
* JkLogStampFormat Directive Handling
*
* JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
*/
static const char *jk_set_log_fmt(cmd_parms * cmd,
void *dummy, const char *log_format)
{
jk_set_log_format(log_format);
return NULL;
}
/*
* JkAutoAlias Directive Handling
*
* JkAutoAlias application directory
*/
static const char *jk_set_auto_alias(cmd_parms * cmd,
void *dummy, char *directory)
{
server_rec *s = cmd->server;
jk_server_conf_t *conf =
(jk_server_conf_t *) ap_get_module_config(s->module_config,
&jk_module);
conf->alias_dir = directory;
if (conf->alias_dir == NULL)
return "JkAutoAlias directory invalid";
return NULL;
}
/*****************************************************************
*
* Actually logging.
*/
typedef const char *(*item_key_func) (request_rec *, char *);
typedef struct
{
item_key_func func;
char *arg;
} request_log_format_item;
static const char *process_item(request_rec * r,
request_log_format_item * item)
{
const char *cp;
cp = (*item->func) (r, item->arg);
return cp ? cp : "-";
}
static void request_log_transaction(request_rec * r, jk_server_conf_t * conf)
{
request_log_format_item *items;
char *str, *s;
int i;
int len = 0;
const char **strs;
int *strl;
apr_array_header_t *format = conf->format;
strs = apr_palloc(r->pool, sizeof(char *) * (format->nelts));
strl = apr_palloc(r->pool, sizeof(int) * (format->nelts));
items = (request_log_format_item *) format->elts;
for (i = 0; i < format->nelts; ++i) {
strs[i] = process_item(r, &items[i]);
}
for (i = 0; i < format->nelts; ++i) {
len += strl[i] = strlen(strs[i]);
}
str = apr_palloc(r->pool, len + 1);
for (i = 0, s = str; i < format->nelts; ++i) {
memcpy(s, strs[i], strl[i]);
s += strl[i];
}
*s = 0;
jk_log(conf->log, JK_LOG_REQUEST, "%s", str);
}
/*****************************************************************
*
* Parsing the log format string
*/
static char *format_integer(apr_pool_t * p, int i)
{
return apr_psprintf(p, "%d", i);
}
static char *pfmt(apr_pool_t * p, int i)
{
if (i <= 0) {
return "-";
}
else {
return format_integer(p, i);
}
}
static const char *constant_item(request_rec * dummy, char *stuff)
{
return stuff;
}
static const char *log_worker_name(request_rec * r, char *a)
{
return apr_table_get(r->notes, JK_WORKER_ID);
}
static const char *log_request_duration(request_rec * r, char *a)
{
return apr_table_get(r->notes, JK_DURATION);
}
static const char *log_request_line(request_rec * r, char *a)
{
/* NOTE: If the original request contained a password, we
* re-write the request line here to contain XXXXXX instead:
* (note the truncation before the protocol string for HTTP/0.9 requests)
* (note also that r->the_request contains the unmodified request)
*/
return (r->parsed_uri.password) ? apr_pstrcat(r->pool, r->method, " ",
apr_uri_unparse(r->pool,
&r->
parsed_uri,
0),
r->
assbackwards ? NULL : " ",
r->protocol, NULL)
: r->the_request;
}
/* These next two routines use the canonical name:port so that log
* parsers don't need to duplicate all the vhost parsing crud.
*/
static const char *log_virtual_host(request_rec * r, char *a)
{
return r->server->server_hostname;
}
static const char *log_server_port(request_rec * r, char *a)
{
return apr_psprintf(r->pool, "%u",
r->server->port ? r->server->
port : ap_default_port(r));
}
/* This respects the setting of UseCanonicalName so that
* the dynamic mass virtual hosting trick works better.
*/
static const char *log_server_name(request_rec * r, char *a)
{
return ap_get_server_name(r);
}
static const char *log_request_uri(request_rec * r, char *a)
{
return r->uri;
}
static const char *log_request_method(request_rec * r, char *a)
{
return r->method;
}
static const char *log_request_protocol(request_rec * r, char *a)
{
return r->protocol;
}
static const char *log_request_query(request_rec * r, char *a)
{
return (r->args != NULL) ? apr_pstrcat(r->pool, "?", r->args, NULL)
: "";
}
static const char *log_status(request_rec * r, char *a)
{
return pfmt(r->pool, r->status);
}
static const char *clf_log_bytes_sent(request_rec * r, char *a)
{
if (!r->sent_bodyct) {
return "-";
}
else {
return apr_off_t_toa(r->pool, r->bytes_sent);
}
}
static const char *log_bytes_sent(request_rec * r, char *a)
{
if (!r->sent_bodyct) {
return "0";
}
else {
return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent);
}
}
static struct log_item_list
{
char ch;
item_key_func func;
} log_item_keys[] = {
{
'T', log_request_duration}, {
'r', log_request_line}, {
'U', log_request_uri}, {
's', log_status}, {
'b', clf_log_bytes_sent}, {
'B', log_bytes_sent}, {
'V', log_server_name}, {
'v', log_virtual_host}, {
'p', log_server_port}, {
'H', log_request_protocol}, {
'm', log_request_method}, {
'q', log_request_query}, {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -