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

📄 mod_include.c

📁 Apache HTTP Server 是一个功能强大的灵活的与HTTP/1.1相兼容的web服务器.这里给出的是Apache HTTP服务器的源码。
💻 C
📖 第 1 页 / 共 5 页
字号:
                }                /* See the Kludge in send_parsed_file for why */                /* Basically, it puts a bread crumb in here, then looks */                /*   for the crumb later to see if its been here.       */                if (rr)                     ap_set_module_config(rr->request_config,                                          &include_module, r);                if (!error_fmt && ap_run_sub_req(rr)) {                    error_fmt = "unable to include \"%s\" in parsed file %s";                }                if (error_fmt) {                    ap_log_rerror(APLOG_MARK, loglevel,                                  0, r, error_fmt, tag_val, r->filename);                    CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,                                         *inserted_head);                }                /* destroy the sub request */                if (rr != NULL) {                    ap_destroy_sub_req(rr);                }            }            else {                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                            "unknown parameter \"%s\" to tag include in %s",                            tag, r->filename);                CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);                return 1;            }        }    }    return 0;}static int handle_echo(include_ctx_t *ctx, apr_bucket_brigade **bb,                        request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,                        apr_bucket **inserted_head){    char       *tag       = NULL;    char       *tag_val   = NULL;    const char *echo_text = NULL;    apr_bucket  *tmp_buck;    apr_size_t e_len;    enum {E_NONE, E_URL, E_ENTITY} encode;    encode = E_ENTITY;    *inserted_head = NULL;    if (ctx->flags & FLAG_PRINTING) {        while (1) {            ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);            if (tag_val == NULL) {                if (tag != NULL) {                    return 1;                }                else {                    return 0;                }            }            if (!strcmp(tag, "var")) {                conn_rec *c = r->connection;                const char *val =                    get_include_var(r, ctx,                                    ap_ssi_parse_string(r, ctx, tag_val, NULL,                                                        MAX_STRING_LEN, 0));                if (val) {                    switch(encode) {                    case E_NONE:                           echo_text = val;                        break;                    case E_URL:                        echo_text = ap_escape_uri(r->pool, val);                          break;                    case E_ENTITY:                         echo_text = ap_escape_html(r->pool, val);                         break;                    }                    e_len = strlen(echo_text);                    tmp_buck = apr_bucket_pool_create(echo_text, e_len,                                                      r->pool, c->bucket_alloc);                }                else {                    include_server_config *sconf=                         ap_get_module_config(r->server->module_config,                                             &include_module);                    tmp_buck = apr_bucket_pool_create(sconf->undefinedEcho,                                                       sconf->undefinedEchoLen,                                                      r->pool, c->bucket_alloc);                }                APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);                if (*inserted_head == NULL) {                    *inserted_head = tmp_buck;                }            }            else if (!strcmp(tag, "encoding")) {                if (!strcasecmp(tag_val, "none")) encode = E_NONE;                else if (!strcasecmp(tag_val, "url")) encode = E_URL;                else if (!strcasecmp(tag_val, "entity")) encode = E_ENTITY;                else {                    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                           "unknown value \"%s\" to parameter \"encoding\" of "                           "tag echo in %s", tag_val, r->filename);                    CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,                                         *inserted_head);                    return 1;                }            }            else {                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                            "unknown parameter \"%s\" in tag echo of %s",                            tag, r->filename);                CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);                return 1;            }        }    }    return 0;}/* error and tf must point to a string with room for at  * least MAX_STRING_LEN characters  */static int handle_config(include_ctx_t *ctx, apr_bucket_brigade **bb,                          request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,                          apr_bucket **inserted_head){    char *tag     = NULL;    char *tag_val = NULL;    char *parsed_string;    apr_table_t *env = r->subprocess_env;    *inserted_head = NULL;    if (ctx->flags & FLAG_PRINTING) {        while (1) {            ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 0);            if (tag_val == NULL) {                if (tag == NULL) {                    return 0;  /* Reached the end of the string. */                }                else {                    return 1;  /* tags must have values. */                }            }            if (!strcmp(tag, "errmsg")) {                if (ctx->error_str_override == NULL) {                    ctx->error_str_override = (char *)apr_palloc(ctx->pool,                                                              MAX_STRING_LEN);                    ctx->error_str = ctx->error_str_override;                }                ap_ssi_parse_string(r, ctx, tag_val, ctx->error_str_override,                                    MAX_STRING_LEN, 0);            }            else if (!strcmp(tag, "timefmt")) {                apr_time_t date = r->request_time;                if (ctx->time_str_override == NULL) {                    ctx->time_str_override = (char *)apr_palloc(ctx->pool,                                                              MAX_STRING_LEN);                    ctx->time_str = ctx->time_str_override;                }                ap_ssi_parse_string(r, ctx, tag_val, ctx->time_str_override,                                    MAX_STRING_LEN, 0);                apr_table_setn(env, "DATE_LOCAL", ap_ht_time(r->pool, date,                                ctx->time_str, 0));                apr_table_setn(env, "DATE_GMT", ap_ht_time(r->pool, date,                                ctx->time_str, 1));                apr_table_setn(env, "LAST_MODIFIED",                               ap_ht_time(r->pool, r->finfo.mtime,                                ctx->time_str, 0));            }            else if (!strcmp(tag, "sizefmt")) {                parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,                                                     MAX_STRING_LEN, 0);                decodehtml(parsed_string);                if (!strcmp(parsed_string, "bytes")) {                    ctx->flags |= FLAG_SIZE_IN_BYTES;                }                else if (!strcmp(parsed_string, "abbrev")) {                    ctx->flags &= FLAG_SIZE_ABBREV;                }            }            else {                apr_bucket *tmp_buck;                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                              "unknown parameter \"%s\" to tag config in %s",                              tag, r->filename);                CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);                return 1;            }        }    }    return 0;}static int find_file(request_rec *r, const char *directive, const char *tag,                     char *tag_val, apr_finfo_t *finfo){    char *to_send = tag_val;    request_rec *rr = NULL;    int ret=0;    char *error_fmt = NULL;    apr_status_t rv = APR_SUCCESS;    if (!strcmp(tag, "file")) {        /* XXX: Port to apr_filepath_merge         * be safe; only files in this directory or below allowed          */        if (!is_only_below(tag_val)) {            error_fmt = "unable to access file \"%s\" "                        "in parsed file %s";        }        else {            ap_getparents(tag_val);    /* get rid of any nasties */            /* note: it is okay to pass NULL for the "next filter" since               we never attempt to "run" this sub request. */            rr = ap_sub_req_lookup_file(tag_val, r, NULL);            if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {                to_send = rr->filename;                if ((rv = apr_stat(finfo, to_send,                     APR_FINFO_GPROT | APR_FINFO_MIN, rr->pool)) != APR_SUCCESS                    && rv != APR_INCOMPLETE) {                    error_fmt = "unable to get information about \"%s\" "                        "in parsed file %s";                }            }            else {                error_fmt = "unable to lookup information about \"%s\" "                            "in parsed file %s";            }        }        if (error_fmt) {            ret = -1;            ap_log_rerror(APLOG_MARK, APLOG_ERR,                          rv, r, error_fmt, to_send, r->filename);        }        if (rr) ap_destroy_sub_req(rr);                return ret;    }    else if (!strcmp(tag, "virtual")) {        /* note: it is okay to pass NULL for the "next filter" since           we never attempt to "run" this sub request. */        rr = ap_sub_req_lookup_uri(tag_val, r, NULL);        if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {            memcpy((char *) finfo, (const char *) &rr->finfo,                   sizeof(rr->finfo));            ap_destroy_sub_req(rr);            return 0;        }        else {            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                        "unable to get information about \"%s\" "                        "in parsed file %s",                        tag_val, r->filename);            ap_destroy_sub_req(rr);            return -1;        }    }    else {        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                    "unknown parameter \"%s\" to tag %s in %s",                    tag, directive, r->filename);        return -1;    }}static int handle_fsize(include_ctx_t *ctx, apr_bucket_brigade **bb,                         request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,                         apr_bucket **inserted_head){    char *tag     = NULL;    char *tag_val = NULL;    apr_finfo_t  finfo;    apr_size_t  s_len;    apr_bucket   *tmp_buck;    char *parsed_string;    *inserted_head = NULL;    if (ctx->flags & FLAG_PRINTING) {        while (1) {            ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);            if (tag_val == NULL) {                if (tag == NULL) {                    return 0;                }                else {                    return 1;                }            }            else {                parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,                                                     MAX_STRING_LEN, 0);                if (!find_file(r, "fsize", tag, parsed_string, &finfo)) {                    /* XXX: if we *know* we're going to have to copy the                     * thing off of the stack anyway, why not palloc buff                     * instead of sticking it on the stack; then we can just                     * use a pool bucket and skip the copy                     */                    char buff[50];                    if (!(ctx->flags & FLAG_SIZE_IN_BYTES)) {                        apr_strfsize(finfo.size, buff);                        s_len = strlen (buff);                    }                    else {                        int l, x, pos = 0;                        char tmp_buff[50];                        apr_snprintf(tmp_buff, sizeof(tmp_buff),                                      "%" APR_OFF_T_FMT, finfo.size);                        l = strlen(tmp_buff);    /* grrr */                        for (x = 0; x < l; x++) {                            if (x && (!((l - x) % 3))) {                                buff[pos++] = ',';                            }                            buff[pos++] = tmp_buff[x];                        }                        buff[pos] = '\0';                        s_len = pos;                    }                    tmp_buck = apr_bucket_heap_create(buff, s_len, NULL,                                                  r->connection->bucket_alloc);                    APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);                    if (*inserted_head == NULL) {                        *inserted_head = tmp_buck;                    }                }                else {                    CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,                                         *inserted_head);                    return 1;                }            }        }    }    return 0;}static int handle_flastmod(include_ctx_t *ctx, apr_bucket_brigade **bb,                            request_rec *r, ap_filter_t *f,                            apr_bucket *head_ptr, apr_bucket **inserted_head){    char *tag     = NULL;    char *tag_val = NULL;    apr_finfo_t  finfo;    apr_size_t  t_len;    apr_bucket   *tmp_buck;    char *parsed_string;    *inserted_head = NULL;    if (ctx->flags & FLAG_PRINTING) {        while (1) {            ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);            if (tag_val == NULL) {                if (tag == NULL) {                    return 0;                }                else {                    return 1;                }            }            else {                parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,                                                     MAX_STRING_LEN, 0);                if (!find_file(r, "flastmod", tag, parsed_string, &finfo)) {                    char *t_val;                    t_val = ap_ht_time(r->pool, finfo.mtime, ctx->time_str, 0);                    t_len = strlen(t_val);                    tmp_buck = apr_bucket_pool_create(t_val, t_len, r->pool,                                                  r->connection->bucket_alloc);                    APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);                    if (*inserted_head == NULL) {

⌨️ 快捷键说明

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