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

📄 mod_log_nw.c

📁 apache 安装教程 apache 安装教程
💻 C
📖 第 1 页 / 共 3 页
字号:
}/* 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[] = {    {        'h', log_remote_host, 0    },    {           'a', log_remote_address, 0     },    {           'A', log_local_address, 0     },    {        'l', log_remote_logname, 0    },    {        'u', log_remote_user, 0    },    {        't', log_request_time, 0    },    {        'T', log_request_duration, 1    },    {        'r', log_request_line, 1    },    {        'f', log_request_file, 0    },    {        'U', log_request_uri, 1    },    {        's', log_status, 1    },    {        'b', clf_log_bytes_sent, 0    },    {        'B', log_bytes_sent, 0    },    {        'i', log_header_in, 0    },    {        'o', log_header_out, 0    },    {        'n', log_note, 0    },    {        'e', log_env_var, 0    },    {        'V', log_server_name, 0    },    {        'v', log_virtual_host, 0    },    {        'p', log_server_port, 0    },    {        'P', log_child_pid, 0    },    {        'H', log_request_protocol, 0    },    {        'm', log_request_method, 0    },    {        'q', log_request_query, 0    },    {        'c', 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;    int log_fd;    multi_log_state *mls = ap_get_module_config(r->server->module_config,&config_log_module);    if ((mls->rotatedaily || mls->rotateinterval) &&        (r->request_time>=cls->time_jump) &&        (*cls->fname!='|') && (strcmp(cls->fname,"/dev/null") != 0)) {        char * fname;        struct tm *time_tmp;        if (mls->rotatedaily) {            time_tmp=localtime(&(r->request_time));            cls->time_jump=r->request_time+((60-time_tmp->tm_sec)+60*(59-time_tmp->tm_min)+3600*(23-time_tmp->tm_hour));        }        else            cls->time_jump = r->request_time + (60*mls->rotateinterval);        fname = ap_pstrcat(r->pool,            ap_server_root_relative(r->pool, cls->fname),            "-",            ap_ht_time(r->pool,r->request_time,"%Y%m%d%H%M",0),            NULL            );        if ((log_fd = open(fname, xfer_flags, xfer_mode)) < 0) {            ap_log_error(APLOG_MARK, APLOG_ERR, r->server,                "could not open transfer log file %s.", fname);        }        else {            dup2 (log_fd, cls->log_fd);            close (log_fd);        }    }    if (cls->fname == NULL) {        return DECLINED;    }    /*     * See if we've got any conditional envariable-controlled logging decisions     * to make.     */    if (cls->condition_var != NULL) {	envar = cls->condition_var;	if (*envar != '!') {	    if (ap_table_get(r->subprocess_env, envar) == NULL) {		return DECLINED;	    }	}	else {	    if (ap_table_get(r->subprocess_env, &envar[1]) != NULL) {		return DECLINED;	    }	}    }    format = cls->format ? cls->format : default_format;    strs = ap_palloc(r->pool, sizeof(char *) * (format->nelts));    strl = ap_palloc(r->pool, sizeof(int) * (format->nelts));    items = (log_format_item *) format->elts;    orig = r;    while (orig->prev) {        orig = orig->prev;    }    while (r->next) {        r = r->next;    }    for (i = 0; i < format->nelts; ++i) {        strs[i] = process_item(r, orig, &items[i]);

⌨️ 快捷键说明

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