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

📄 mod_log_config.c

📁 apache 安装教程 apache 安装教程
💻 C
📖 第 1 页 / 共 3 页
字号:
    else {                      /* CLF format */        char sign = (timz < 0 ? '-' : '+');        if (timz < 0) {            timz = -timz;        }        ap_snprintf(tstr, sizeof(tstr), "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",                t->tm_mday, ap_month_snames[t->tm_mon], t->tm_year+1900,                 t->tm_hour, t->tm_min, t->tm_sec,                sign, timz / 60, timz % 60);    }    return ap_pstrdup(r->pool, tstr);}static const char *log_request_duration(request_rec *r, char *a){    return ap_psprintf(r->pool, "%ld", time(NULL) - r->request_time);}/* 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 ap_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_child_pid(request_rec *r, char *a){    return ap_psprintf(r->pool, "%ld", (long) getpid());}static const char *log_connection_status(request_rec *r, char *a){    if (r->connection->aborted)        return "X";    if ((r->connection->keepalive) &&        ((r->server->keep_alive_max - r->connection->keepalives) > 0)) {        return "+";    }    return "-";}/***************************************************************** * * Parsing the log format string */static struct log_item_list {    char ch;    item_key_func func;    int want_orig_default;} log_item_keys[] = {    {           'a', log_remote_address, 0     },    {           'A', log_local_address, 0     },    {        'b', clf_log_bytes_sent, 0    },    {        'B', log_bytes_sent, 0    },    {        'c', log_connection_status, 0    },    {        'e', log_env_var, 0    },    {        'f', log_request_file, 0    },    {        'h', log_remote_host, 0    },    {        'H', log_request_protocol, 0    },    {        'i', log_header_in, 0    },    {        'l', log_remote_logname, 0    },    {        'm', log_request_method, 0    },    {        'n', log_note, 0    },    {        'o', log_header_out, 0    },    {        'p', log_server_port, 0    },    {        'P', log_child_pid, 0    },    {        'q', log_request_query, 0    },    {        'r', log_request_line, 1    },    {        's', log_status, 1    },    {        't', log_request_time, 0    },    {        'T', log_request_duration, 1    },    {        'u', log_remote_user, 0    },    {        'U', log_request_uri, 1    },    {        'v', log_virtual_host, 0    },    {        'V', log_server_name, 0    },    {        'X', log_connection_status, 0    },    {        '\0'    }};static struct log_item_list *find_log_func(char k){    int i;    for (i = 0; log_item_keys[i].ch; ++i)        if (k == log_item_keys[i].ch) {            return &log_item_keys[i];        }    return NULL;}static char *parse_log_misc_string(pool *p, log_format_item *it,                                   const char **sa){    const char *s;    char *d;    it->func = constant_item;    it->conditions = NULL;    s = *sa;    while (*s && *s != '%') {	s++;    }    /*     * This might allocate a few chars extra if there's a backslash     * escape in the format string.     */    it->arg = ap_palloc(p, s - *sa + 1);    d = it->arg;    s = *sa;    while (*s && *s != '%') {	if (*s != '\\') {	    *d++ = *s++;	}	else {	    s++;	    switch (*s) {	    case '\\':		*d++ = '\\';		s++;		break;	    case 'n':		*d++ = '\n';		s++;		break;	    case 't':			*d++ = '\t';		s++;		break;	    default:		/* copy verbatim */		*d++ = '\\';		/*		 * Allow the loop to deal with this *s in the normal		 * fashion so that it handles end of string etc.		 * properly.		 */		break;	    }	}    }    *d = '\0';    *sa = s;    return NULL;}static char *parse_log_item(pool *p, log_format_item *it, const char **sa){    const char *s = *sa;    if (*s != '%') {        return parse_log_misc_string(p, it, sa);    }    ++s;    it->condition_sense = 0;    it->conditions = NULL;    it->want_orig = -1;    it->arg = "";               /* For safety's sake... */    while (*s) {        int i;        struct log_item_list *l;        switch (*s) {        case '!':            ++s;            it->condition_sense = !it->condition_sense;            break;        case '<':            ++s;            it->want_orig = 1;            break;        case '>':            ++s;            it->want_orig = 0;            break;        case ',':            ++s;            break;        case '{':            ++s;            it->arg = ap_getword(p, &s, '}');            break;        case '0':        case '1':        case '2':        case '3':        case '4':        case '5':        case '6':        case '7':        case '8':        case '9':            i = *s - '0';            while (ap_isdigit(*++s)) {                i = i * 10 + (*s) - '0';            }            if (!it->conditions) {                it->conditions = ap_make_array(p, 4, sizeof(int));            }            *(int *) ap_push_array(it->conditions) = i;            break;        default:            l = find_log_func(*s++);            if (!l) {                char dummy[2];                dummy[0] = s[-1];                dummy[1] = '\0';                return ap_pstrcat(p, "Unrecognized LogFormat directive %",                               dummy, NULL);            }            it->func = l->func;            if (it->want_orig == -1) {                it->want_orig = l->want_orig_default;            }            *sa = s;            return NULL;        }    }    return "Ran off end of LogFormat parsing args to some directive";}static array_header *parse_log_string(pool *p, const char *s, const char **err){    array_header *a = ap_make_array(p, 30, sizeof(log_format_item));    char *res;    while (*s) {        if ((res = parse_log_item(p, (log_format_item *) ap_push_array(a), &s))) {            *err = res;            return NULL;        }    }    s = "\n";    parse_log_item(p, (log_format_item *) ap_push_array(a), &s);    return a;}/***************************************************************** * * Actually logging. */static const char *process_item(request_rec *r, request_rec *orig,                          log_format_item *item){    const char *cp;    /* First, see if we need to process this thing at all... */    if (item->conditions && item->conditions->nelts != 0) {        int i;        int *conds = (int *) item->conditions->elts;        int in_list = 0;        for (i = 0; i < item->conditions->nelts; ++i) {            if (r->status == conds[i]) {                in_list = 1;                break;            }        }        if ((item->condition_sense && in_list)            || (!item->condition_sense && !in_list)) {            return "-";        }    }    /* We do.  Do it... */    cp = (*item->func) (item->want_orig ? orig : r, item->arg);    return cp ? cp : "-";}#ifdef BUFFERED_LOGSstatic void flush_log(config_log_state *cls){    if (cls->outcnt && cls->log_fd != -1) {        write(cls->log_fd, cls->outbuf, cls->outcnt);        cls->outcnt = 0;    }}#endifstatic int config_log_transaction(request_rec *r, config_log_state *cls,                                  array_header *default_format){    log_format_item *items;    char *str, *s;    const char **strs;    int *strl;    request_rec *orig;    int i;    int len = 0;    array_header *format;    char *envar;    if (cls->fname == NULL) {        return DECLINED;    }    /*

⌨️ 快捷键说明

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