📄 mod_include.c
字号:
ap_log_rerror(APLOG_MARK, (ctx->flags & SSI_FLAG_PRINTING) ? APLOG_ERR : APLOG_WARNING, 0, r, "missing argument for include element in %s", r->filename); } if (!(ctx->flags & SSI_FLAG_PRINTING)) { return APR_SUCCESS; } if (!ctx->argc) { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); return APR_SUCCESS; } while (1) { char *tag = NULL; char *tag_val = NULL; request_rec *rr = NULL; char *error_fmt = NULL; char *parsed_string; ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_DECODED); if (!tag || !tag_val) { break; } if (strcmp(tag, "virtual") && strcmp(tag, "file")) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "unknown parameter " "\"%s\" to tag include in %s", tag, r->filename); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } parsed_string = ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME); if (tag[0] == 'f') { char *newpath; apr_status_t rv; /* be safe; only files in this directory or below allowed */ rv = apr_filepath_merge(&newpath, NULL, parsed_string, APR_FILEPATH_SECUREROOTTEST | APR_FILEPATH_NOTABSOLUTE, ctx->dpool); if (rv != APR_SUCCESS) { error_fmt = "unable to include file \"%s\" in parsed file %s"; } else { rr = ap_sub_req_lookup_file(newpath, r, f->next); } } else { rr = ap_sub_req_lookup_uri(parsed_string, r, f->next); } if (!error_fmt && rr->status != HTTP_OK) { error_fmt = "unable to include \"%s\" in parsed file %s"; } if (!error_fmt && (ctx->flags & SSI_FLAG_NO_EXEC) && rr->content_type && strncmp(rr->content_type, "text/", 5)) { error_fmt = "unable to include potential exec \"%s\" in parsed " "file %s"; } /* See the Kludge in includes_filter 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, APLOG_ERR, 0, r, error_fmt, tag_val, r->filename); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); } /* Do *not* destroy the subrequest here; it may have allocated * variables in this r->subprocess_env in the subrequest's * r->pool, so that pool must survive as long as this request. * Yes, this is a memory leak. */ if (error_fmt) { break; } } return APR_SUCCESS;}/* * <!--#echo [encoding="..."] var="..." [encoding="..."] var="..." ... --> */static apr_status_t handle_echo(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb){ enum {E_NONE, E_URL, E_ENTITY} encode; request_rec *r = f->r; if (!ctx->argc) { ap_log_rerror(APLOG_MARK, (ctx->flags & SSI_FLAG_PRINTING) ? APLOG_ERR : APLOG_WARNING, 0, r, "missing argument for echo element in %s", r->filename); } if (!(ctx->flags & SSI_FLAG_PRINTING)) { return APR_SUCCESS; } if (!ctx->argc) { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); return APR_SUCCESS; } encode = E_ENTITY; while (1) { char *tag = NULL; char *tag_val = NULL; ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_DECODED); if (!tag || !tag_val) { break; } if (!strcmp(tag, "var")) { const char *val; const char *echo_text = NULL; apr_size_t e_len; val = get_include_var(ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME), ctx); if (val) { switch(encode) { case E_NONE: echo_text = val; break; case E_URL: echo_text = ap_escape_uri(ctx->dpool, val); break; case E_ENTITY: echo_text = ap_escape_html(ctx->dpool, val); break; } e_len = strlen(echo_text); } else { echo_text = ctx->intern->undefined_echo; e_len = ctx->intern->undefined_echo_len; } APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create( apr_pmemdup(ctx->pool, echo_text, e_len), e_len, ctx->pool, f->c->bucket_alloc)); } 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); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "unknown parameter " "\"%s\" in tag echo of %s", tag, r->filename); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } } return APR_SUCCESS;}/* * <!--#config [timefmt="..."] [sizefmt="..."] [errmsg="..."] * [echomsg="..."] --> */static apr_status_t handle_config(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb){ request_rec *r = f->r; apr_table_t *env = r->subprocess_env; if (!ctx->argc) { ap_log_rerror(APLOG_MARK, (ctx->flags & SSI_FLAG_PRINTING) ? APLOG_ERR : APLOG_WARNING, 0, r, "missing argument for config element in %s", r->filename); } if (!(ctx->flags & SSI_FLAG_PRINTING)) { return APR_SUCCESS; } if (!ctx->argc) { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); return APR_SUCCESS; } while (1) { char *tag = NULL; char *tag_val = NULL; ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_RAW); if (!tag || !tag_val) { break; } if (!strcmp(tag, "errmsg")) { ctx->error_str = ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME); } else if (!strcmp(tag, "echomsg")) { ctx->intern->undefined_echo = ap_ssi_parse_string(ctx, tag_val, NULL, 0,SSI_EXPAND_DROP_NAME); ctx->intern->undefined_echo_len=strlen(ctx->intern->undefined_echo); } else if (!strcmp(tag, "timefmt")) { apr_time_t date = r->request_time; ctx->time_str = ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME); 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")) { char *parsed_string; parsed_string = ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME); if (!strcmp(parsed_string, "bytes")) { ctx->flags |= SSI_FLAG_SIZE_IN_BYTES; } else if (!strcmp(parsed_string, "abbrev")) { ctx->flags &= SSI_FLAG_SIZE_ABBREV; } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "unknown value " "\"%s\" to parameter \"sizefmt\" of tag config " "in %s", parsed_string, r->filename); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "unknown parameter " "\"%s\" to tag config in %s", tag, r->filename); SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } } return APR_SUCCESS;}/* * <!--#fsize virtual|file="..." [virtual|file="..."] ... --> */static apr_status_t handle_fsize(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb){ request_rec *r = f->r; if (!ctx->argc) { ap_log_rerror(APLOG_MARK, (ctx->flags & SSI_FLAG_PRINTING) ? APLOG_ERR : APLOG_WARNING, 0, r, "missing argument for fsize element in %s", r->filename); } if (!(ctx->flags & SSI_FLAG_PRINTING)) { return APR_SUCCESS; } if (!ctx->argc) { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); return APR_SUCCESS; } while (1) { char *tag = NULL; char *tag_val = NULL; apr_finfo_t finfo; char *parsed_string; ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_DECODED); if (!tag || !tag_val) { break; } parsed_string = ap_ssi_parse_string(ctx, tag_val, NULL, 0, SSI_EXPAND_DROP_NAME); if (!find_file(r, "fsize", tag, parsed_string, &finfo)) { char *buf; apr_size_t len; if (!(ctx->flags & SSI_FLAG_SIZE_IN_BYTES)) { buf = apr_strfsize(finfo.size, apr_palloc(ctx->pool, 5)); len = 4; /* omit the \0 terminator */ } else { apr_size_t l, x, pos; char *tmp; tmp = apr_psprintf(ctx->dpool, "%" APR_OFF_T_FMT, finfo.size); len = l = strlen(tmp); for (x = 0; x < l; ++x) { if (x && !((l - x) % 3)) { ++len; } } if (len == l) { buf = apr_pstrmemdup(ctx->pool, tmp, len); } else { buf = apr_palloc(ctx->pool, len); for (pos = x = 0; x < l; ++x) { if (x && !((l - x) % 3)) { buf[pos++] = ','; } buf[pos++] = tmp[x]; } } } APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(buf, len, ctx->pool, f->c->bucket_alloc)); } else { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); break; } } return APR_SUCCESS;}/* * <!--#flastmod virtual|file="..." [virtual|file="..."] ... --> */static apr_status_t handle_flastmod(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb){ request_rec *r = f->r; if (!ctx->argc) { ap_log_rerror(APLOG_MARK, (ctx->flags & SSI_FLAG_PRINTING) ? APLOG_ERR : APLOG_WARNING, 0, r, "missing argument for flastmod element in %s", r->filename); } if (!(ctx->flags & SSI_FLAG_PRINTING)) { return APR_SUCCESS; } if (!ctx->argc) { SSI_CREATE_ERROR_BUCKET(ctx, f, bb); return APR_SUCCESS; } while (1) { char *tag = NULL; char *tag_val = NULL; apr_finfo_t finfo; char *parsed_string; ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, SSI_VALUE_DECODED); if (!tag || !tag_val) { break; } parsed_string = ap_s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -